Skip to content

Commit df26a3b

Browse files
Add files via upload
1 parent 6c5f314 commit df26a3b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Unique Paths/Unique_Paths.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 第一种思路,使用组合计算公式
2+
# 36ms 96.05%
3+
class Solution:
4+
def uniquePaths(self, m, n):
5+
"""
6+
:type m: int
7+
:type n: int
8+
:rtype: int
9+
"""
10+
def factorial(num):
11+
if num is 0:
12+
return 1
13+
else:
14+
return num * factorial(num - 1)
15+
16+
def combination(m, n):
17+
return factorial(n) // factorial(m) // factorial(n - m)
18+
19+
return combination(m - 1, m - 1 + n - 1)

0 commit comments

Comments
 (0)