62. Unique Paths
Approach 1: Combinatorics
class Solution(object):
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
di = {0:1, 1:1, 2:2}
def factorial(n):
if n in di:
return di[n]
else:
di[n] = n*factorial(n-1)
return di[n]
return int(factorial(m+n-2)/(factorial(m-1)*factorial(n-1)))Approach 2: Use multiplication instead of factorial
Approach 3: Dynamic Programming
Last updated