Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. class Solution:
  2.     def __init__(self):
  3.         self.memo = {}
  4.     def uniquePaths(self, m, n):
  5.         """
  6.        :type m: int
  7.        :type n: int
  8.        :rtype: int
  9.        """
  10.         if m == 1 or n == 1:
  11.             return 1
  12.        
  13.         if m < n:
  14.             small, big = m, n
  15.         else:
  16.             small, big = n, m
  17.        
  18.         key = "{}:{}".format(small, big)
  19.        
  20.         if not key in self.memo:
  21.             self.memo[key] = self.uniquePaths(m - 1, n) + self.uniquePaths(m, n - 1)
  22.            
  23.        
  24.         return self.memo[key]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement