```
cache = {}
def uniquePaths(self, m, n):
"""
:type m: int
:type n: int
:rtype: int
"""
if (m,n) in self.cache:
return self.cache[m,n]
if m < 1 or n < 1:
return 0
if m == n == 1:
return 1
self.cache[m,n] = self.uniquePaths(m-1,n) + self.uniquePaths(m,n-1)
return self.cache[m,n]
```