Skip to content

Commit ad39058

Browse files
committed
Solve: Unique Paths
1 parent 7ed033d commit ad39058

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

โ€Žunique-paths/KwonNayeon.pyโ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Constraints:
3+
- 1 <= m, n <= 100
4+
5+
Time Complexity: O(1)
6+
- math.comb() ์‚ฌ์šฉ
7+
8+
Space Complexity: O(1)
9+
- ์ถ”๊ฐ€ ๊ณต๊ฐ„ ํ•„์š”์—†์Œ
10+
11+
ํ’€์ด ๋ฐฉ๋ฒ•:
12+
- ์˜ค๋ฅธ์ชฝ ์•„๋ž˜ ์ฝ”๋„ˆ๋กœ ๊ฐ€๋Š” ์œ ๋‹ˆํฌํ•œ ๋ฐฉ๋ฒ•์˜ ๊ฐฏ์ˆ˜ ์ฐพ๊ธฐ
13+
1. (m-1)๋ฒˆ ์•„๋ž˜๋กœ, (n-1)๋ฒˆ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฐ€์•ผํ•จ -> ์ด (m+n-2)๋ฒˆ ์ด๋™
14+
2. ๊ฒฐ๊ตญ (m+n-2)๋ฒˆ์˜ ์ด๋™ ์ค‘ (n-1)๋ฒˆ์˜ ์˜ค๋ฅธ์ชฝ ์ด๋™์„ ์„ ํƒํ•˜๋Š” ์กฐํ•ฉ์˜ ์ˆ˜
15+
3. Combination ๊ณต์‹ ์ ์šฉ: (m+n-2)C(n-1)
16+
17+
Further Consideration:
18+
- DP๋กœ ํ’€์–ด๋ณด๊ธฐ
19+
"""
20+
class Solution:
21+
def uniquePaths(self, m: int, n: int) -> int:
22+
from math import comb
23+
return comb(m+n-2, n-1)

0 commit comments

Comments
ย (0)