Coordinate
63 Unique Path II
Now consider if some obstacles are added to the grids. How many unique paths would there be
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
m, n = len(obstacleGrid), len(obstacleGrid[0])
dp = [0] * n
for j in range(n):
if obstacleGrid[0][j] == 1: break
dp[j] = 1
for i in range(1, m):
if obstacleGrid[i][0] == 1:
dp[0] = 0
for j in range(1, n):
dp[j] = dp[j] + dp[j-1] if obstacleGrid[i][j] == 0 else 0
return dp[n-1]Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Jump game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Your goal is to reach the last index in the minimum number of jumps.
Magicl Vowel
A magical sub-sequence of a string S is a sub-sequence of S that contains all five vowels in order. Find the length of largest magical sub-sequence of a string S. For example, if S = aeeiooua, then aeiou and aeeioou are magical sub-sequences but aeio and aeeioua are not.
State: S到index i, char到index j目前longest voewl string number
Func: dp[i][j] = if(s[i]==c[j]) max(dp[i-1][j], dp[i][j-1]) + 1, else max(dp[i-1][j], dp[i][j-1])
Ans: dp[m][n] must >= char length, otherwise return 0;
Last updated
Was this helpful?