File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ https://leetcode.com/problems/unique-paths/description/
3+
4+ ์๋๋ก ์ด๋ ํน์ (1, 0)
5+ ์ค๋ฅธ์ชฝ ์ด๋๋ง ๊ฐ๋ฅ (0, 1)
6+
7+ m => rows, n = cols
8+ ๋ก๋ด์ด (0, 0)์์ (m-1, n-1)์ ๋์ฐฉ ๊ฐ๋ฅํ unique paths ๊ฐ์๋ฅผ ๋ฐํ
9+
10+ ํ์ด ์๊ฐ: 16๋ถ
11+ ์ฒ์์ ์ด๋ป๊ฒ ํ์ด์ผ ํ ์ค ๋ชฐ๋์ง๋ง, ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ณด๋ฉฐ ๋์ ๊ท์น์ ์ฐพ์ (์, ์ผ์ชฝ ๊ฐ ๋ํด๋๊ฐ๊ธฐ)
12+
13+ TC: O(m * n)
14+ SC: O(m * n)
15+ """
16+
17+ class Solution :
18+ def uniquePaths (self , m : int , n : int ) -> int :
19+ paths = [[0 ] * n for _ in range (m )]
20+ paths [0 ][0 ] = 1
21+
22+ for i in range (m ):
23+ for j in range (n ):
24+ if i - 1 >= 0 and j - 1 >= 0 :
25+ paths [i ][j ] = paths [i - 1 ][j ] + paths [i ][j - 1 ]
26+ else :
27+ paths [i ][j ] = 1
28+
29+ return paths [m - 1 ][n - 1 ]
You canโt perform that action at this time.
0 commit comments