Remember Pascal's triangle from middle school? Super short Python solution


  • 0
    M
    def combination(n, k):
        Result = 1.0
        for i in range(1, k+1):
            Result *= (n - (k - i))/float(i)
        return int(Result + 0.5)
       
    class Solution(object):
        def uniquePaths(self, m, n):
            return combination(m + n - 2, m - 1)

  • 0
    S

    So concise and smart.


Log in to reply
 

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