it's just simple combinatorics formula, no DP :)


  • 0
    I

    It's actually (m + n - 2)! / ((m - 1)! * (n - 1)!)

    class Solution(object):
        def uniquePaths(self, m, n):
            """
            :type m: int
            :type n: int
            :rtype: int
            """
            if m > n:
                m, n = n, m
            i = n
            j = 1
            res = 1
            for k in range(m - 1):
                res *= i
                #res = res * 1.0 / j
                i += 1
                #j += 1
            res2 = 1
            for k in range(m - 1):
                res2 *= j
                j += 1
            return int(res / res2)
    

  • 0

    nice formula!
    good math level


Log in to reply
 

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