My Python solution, just one line


  • 1
    M
    class Solution:
    # @return factorial value of n
    def factorial(self,n):
        if n==0:
            return 1
        else:
            return reduce(lambda x,y:x*y,range(1,n+1))
    # @return a list of lists of integers
    def generate(self, numRows):
        result = map(lambda i:map(lambda x:self.factorial(i)/self.factorial(x)/self.factorial(i-x),range(i+1)),range(numRows))
        return result
    

    Firstly, define a function to calculate the factorial value of n, then create the list directly


  • 3
    J

    too mathec

    : and maybe hard for reading \ understanding


Log in to reply
 

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