8000 62, combination, m ↓ steps, n → steps · xzlin/LeetCode_Python_Accepted@5ed6b8a · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

Commit 5ed6b8a

Browse files
committed
62, combination, m ↓ steps, n → steps
1 parent 92ebf77 commit 5ed6b8a

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

62_Unique_Paths.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
# 2015-08-31 Runtime: 56 ms
1+
# 2016-03-26 61 tests, 44 ms
22
class Solution(object):
33
def uniquePaths(self, m, n):
44
"""
55
:type m: int
66
:type n: int
77
:rtype: int
88
"""
9-
# C(m-1+n-1)(m-1)
10-
if m > n: m, n = n, m
11-
res = 1
12-
for i in xrange(1, m):
13-
res = res * (m + n - 1 - i) / i
14-
return res
9+
m, n = m - 1, n - 1
10+
return math.factorial(m + n) / math.factorial(m) / math.factorial(n)

0 commit comments

Comments
 (0)
0