forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsungjinwi.py
More file actions
25 lines (21 loc) ยท 848 Bytes
/
sungjinwi.py
File metadata and controls
25 lines (21 loc) ยท 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""
ํ์ด :
matrix์ 0th row, 0th column์ 1๋ก ๋๊ณ
matrix์ ๊ฐ ์นธ์ผ๋ก ์ค๋ ๋ฐฉ๋ฒ์ ๊ณ์ฐํ๋ค
ํ์ฌ ์นธ์ผ๋ก ์ค๋ ๋ฐฉ๋ฒ์ ์ผ์ชฝ์์ ๋๋ ์์ชฝ์์ ์ค๋ ๋ฐฉ๋ฒ ๋ฟ์ด๋ฏ๋ก
๋์ ๋ํ ๊ฐ์ด ํ์ฌ ์นธ์ ์ค๋ ๋ฐฉ๋ฒ์ ์์ด๋ค
์ ์ฒด matrix๊ฐ ์๋ row ํ ์ค ๋งํผ์ ๋ฐฐ์ด, cur๋ฅผ ์ด์ฉํ์ฌ
row์ ๋ํด ๋ฐ๋ณต๋ฌธ์ ๋๊ณ cur์ ๋ง์ง๋ง ์์๋ฅผ return
matrix์ ํฌ๊ธฐ m * n
TC : O(M * N)
matrix์ ๋ชจ๋ ์์๋ฅผ ์ํํ๋ฏ๋ก
SC : O(N)
cur์ ํฌ๊ธฐ๊ฐ n์ ๋น๋กํ๋ฏ๋ก
"""
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
cur = [1] * n
for _ in range(1, m) :
for i in range(1, n) :
cur[i] = cur[i - 1] + cur[i]
return cur[-1]