Unique Path

class Solution(object):
    def uniquePaths(self, m, n):
        """
        :type m: int
        :type n: int
        :rtype: int
        """
        if m > n:
            m, n = n, m

        dp = [1] * m
        for i in range(1, n):
            for j in range(1, m):
                dp[j] = dp[j - 1] + dp[j]
        return dp[-1]

Last updated