Python DP solution


  • 0
    G

    Just climb stair in 2D

    class Solution:
        # @return an integer
        def __init__(self):
            self.wayAtPos = {}
    
        def uniquePaths(self, m, n):
            if (m, n) in self.wayAtPos:
                return self.wayAtPos[(m, n)]
            if m < 1 or n < 1:
                return 0
            if m == 1 or n == 1:
                return 1
            
            self.wayAtPos[(m, n)] = self.uniquePaths(m-1, n) + self.uniquePaths(m, n-1)
            
            return self.wayAtPos[(m, n)]

  • 0
    C

    I got "Time Limit Exceeded" with this code......


  • 0
    G

    Maybe just bad luck for you?

    61 / 61 test cases passed.
    Status: Accepted
    Runtime: 107 ms
    Submitted: 0 minutes ago
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.