Skip to content

Commit a647a2b

Browse files
author
Jinbeom
committed
Unique Paths Solution
1 parent 579e493 commit a647a2b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

unique-paths/kayden.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from math import comb
2+
class Solution:
3+
# 시간복잡도: O(m+n)
4+
# 공간복잡도: O(1)
5+
def uniquePaths(self, m: int, n: int) -> int:
6+
return comb(m+n-2, n-1) # m+n-2Cn-1
7+
8+
# 시간복잡도: O(m*n)
9+
# 공간복잡도: O(n)
10+
def uniquePaths2(self, m: int, n: int) -> int:
11+
dp = [1] * n
12+
13+
for _ in range(1, m):
14+
for j in range(1, n):
15+
dp[j] = dp[j-1] + dp[j]
16+
17+
return dp[n-1]

0 commit comments

Comments
 (0)