1 line python, math solution


  • 0
    S

    Imaging the (m x n) matrix to be a declining triangle,
    then the point (m, n) will be at row (m+n-2) and col (n-1),
    so its value can be easily calculated by the definition of Pascal's Triangle

    from math import *
    
    class Solution(object):
        def uniquePaths(self, m, n):
            """
            :type m: int
            :type n: int
            :rtype: int
            """
            return factorial(m+n-2)/factorial(n-1)/factorial(m-1)
                    
    

Log in to reply
 

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