骨骼清奇:
LC 62
LC 337 House Robber III
LC 486 Predict the Winner
LC 312 Burst Balloons
Onsite: 考察dp的解滓,類似與有多少條路徑秒赤,從起點到終點,在一個二維grid上,leetcode有相似的題吱瘩,然后如果遇到障礙或者必須經(jīng)過某些位置的話咋辦
[Uber] LC 91 Decode Ways
[Uber] 911 Online Election
[Uber] LC 72 Edit Distance
LC六二
A robot is located at the top-left corner of a m x n grid. The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. How many possible unique paths are there?
著名變種:給定一個矩形的長寬肿嘲,用多少種方法可以從左上角走到右上角 (每一步晋南,只能向正右嵌削、右上 或 右下走):整個矩形遍歷做DP即可,不需要想復雜偿警。
-follow up:如果給矩形里的三個點躏救,要求解決上述問題的同時,遍歷這三個點 (切割矩形螟蒸,一個一個地做DP盒使,然后相加)
-follow up:如何判斷這三個點一個是合理的睁本,即存在遍歷這三個點的路經(jīng)
-follow up:如果給你一個H,要求你的路徑必須向下越過H這個界忠怖。
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
if not m or not n: return 0
dp = [[1]*n for _ in range(m)]
for i in range(1,m):
for j in range(1,n):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[-1][-1]