Skip to content

Commit e19e8c1

Browse files
committed
add unique-paths
1 parent 1ff9936 commit e19e8c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

unique-paths/i-mprovising.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Time, space complexity O(m*n)
3+
4+
Dynamic programming
5+
"""
6+
7+
class Solution:
8+
def uniquePaths(self, m: int, n: int) -> int:
9+
dp = [[0 for _ in range(n)] for _ in range(m)]
10+
dp[0] = [1 for _ in range(n)]
11+
12+
for i in range(1, m):
13+
for j in range(n):
14+
if i == 0:
15+
continue
16+
if j == 0:
17+
dp[i][j] = 1
18+
continue
19+
dp[i][j] = dp[i-1][j] + dp[i][j-1]
20+
21+
return dp[-1][-1]

0 commit comments

Comments
 (0)