Leetcode_DP_Unique Jumps

Leetcode_DP_Unique Jumps_第1张图片

class Solution:
    def __init__(self):
        self.memory = {}
    def uniquePaths(self, m: int, n: int) -> int:
        if (m,n) in self.memory:
            return self.memory[(m,n)]
        if m==1 or n==1:
            return 1
        if m<1 or n<1:
            return 0
        self.memory[(m,n)]=self.uniquePaths(m-1,n)+self.uniquePaths(m,n-1)
        return self.memory[(m,n)]

 

你可能感兴趣的:(动态规划,编程笔试,Leetcode)