Skip to content

Commit 60d0ed2

Browse files
committed
unique-paths solution
1 parent 32f43a4 commit 60d0ed2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

unique-paths/yyyyyyyyyKim.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def uniquePaths(self, m: int, n: int) -> int:
3+
4+
# DP (시간복잡도 O(m*n), 공간복잡도 O(m*n))
5+
# 모든 1행과 1열은 경로가 1개이므로 1로 배열 초기화.
6+
dp = [[1]*n for _ in range(m)]
7+
8+
for i in range(1,m):
9+
for j in range(1,n):
10+
# 현재위치 경로 경우의 수 = 위쪽 + 왼쪽
11+
dp[i][j] = dp[i-1][j] + dp[i][j-1]
12+
13+
return dp[m-1][n-1]

0 commit comments

Comments
 (0)