Simple python DP solution. O(n) space and O(n^2) time.


  • 0
    T
    class Solution(object):
        def uniquePaths(self, m, n):
            """
            :type m: int
            :type n: int
            :rtype: int
            """
            re=[1]*m
            for j in range(n-1):
                for i in range(1,len(re)):
                    re[i]=re[i-1]+re[i]
            return re[-1]
    

Log in to reply
 

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