Catalogue
Count
62. Unique Paths
1 | # Time : O(mn), Space : O(mn) |
1 | # Time : O(mn), Space : O(n) |
Follow Up
- Given three points in the matrix, find the path number that traverse these 3 points
- do it seperated three matrix, then add together
- How to validate the three points?
- If give you a “H”, ask your path have to cross “H”
63. Unique Paths II
1 | class Solution: |
118. Pascal’s Triangle
1 | class Solution(object): |
119. Pascal’s Triangle II
1 | class Solution(object): |
Minimum
64. Minimum Path Sum
- Time : O(mn), Space : O(min(m, n))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18class Solution(object):
def minPathSum(self, grid):
if not grid:
return 0
m, n = len(grid), len(grid[0])
dp = [0] * n
for i in range(n):
dp[i] = grid[0][i] + (dp[i-1] if i >0 else 0)
for i in range(1, m):
for j in range(n):
if j == 0:
dp[j] += grid[i][j]
continue
dp[j] = min(dp[j], dp[j-1]) + grid[i][j]
return dp[-1]