Skip to content

Commit ffc63d7

Browse files
authored
Create minimum-sideway-jumps.py
1 parent de1dd97 commit ffc63d7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/minimum-sideway-jumps.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def minSideJumps(self, obstacles):
6+
"""
7+
:type obstacles: List[int]
8+
:rtype: int
9+
"""
10+
dp = [1, 0, 1]
11+
for i in obstacles:
12+
if i:
13+
dp[i-1] = float("inf")
14+
for j in xrange(3):
15+
if j+1 != i:
16+
dp[j] = min(dp[0]+(j != 0), dp[1]+(j != 1), dp[2]+(j != 2))
17+
return min(dp)

0 commit comments

Comments
 (0)