easy understand python DP solution O(n) space


  • 0
    G
    def uniquePaths(self,m,n):
            dp=[1]*n
            for i in range(1,m):
                for j in range(1,n):
                    dp[j]=dp[j-1]+dp[j]
            return dp[-1]
    

    Basic idea is that the new dp[j] is decided by original dp[j] (its top), and new dp[j-1] (its left)


Log in to reply
 

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