My accept code for Pascal's Triangle, by python, a little long.


  • 0
    N
    class Solution:
        # @return a list of lists of integers
        def generate(self, numRows):
        	def sum2(prev_l, numRows):
        		if numRows == 0:
        			return
        		prev_l.insert(0,0)
        		prev_l.append(0)
        		new_l = []
        		for i in range(len(prev_l) - 1) : 
        			new_l.append(prev_l[i] + prev_l[i+1])
    
        		prev_l.remove(0)
        		prev_l.pop()
    
        		result_l.append(new_l)
        		sum2(new_l, numRows - 1)
    
        	if numRows <= 0:
        		return []
        	elif numRows == 1:
        		return [[1]]
    
        	result_l = []
        	init_l = [1]
        	result_l.append(init_l)
        	sum2(init_l, numRows - 1)
    
        	return result_l
    

    My accept code for Pascal's Triangle, by python, a little long.


Log in to reply
 

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