My Python solutions


  • 0
    B
    class Solution(object):
        def generate(self, numRows):
            rows = [[1] for x in range(numRows)]
            for i in range(1,numRows):
                rows[i] += [ rows[i - 1][x] + rows[i - 1][x - 1] for x in range(1, i)] + [1]
            return rows
    
    
    
    class Solution(object):
        def generate(self, numRows):
            rows = []
            for i in range(numRows):
                rows += [1],
                if i == 0:
                    continue
                else:
                    rows[-1] += [ rows[-2][x] + rows[-2][x - 1] for x in range(1, i)] + [1]
            return rows

Log in to reply
 

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