Leetcode_DP_

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)]

 

彼は183元記事に公開 ウォン称賛91 ビュー9985を

おすすめ

転載: blog.csdn.net/weixin_45405128/article/details/105354825