It is quite comfortable to use Python handling this problem.


  • 1
    V
    class Solution:
    # @return a list of lists of integers
    def generate(self, numRows):
        list = []
        # if numRows == 0:
        #     return list
        temp = []
        for i in range(1, numRows + 1):
            temp = [1 for val in range(i)]
            if (i > 2):
                for j in range (1, i - 1):
                    temp[j] = list[i-2][j-1] + list[i-2][j]
            list.append(temp)
        
        return list  
    

    My solution is above.


Log in to reply
 

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