We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ed033d commit ad39058Copy full SHA for ad39058
โunique-paths/KwonNayeon.pyโ
@@ -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