1. initialize tri to [1]. When rowindex = 0, the return result is: 1, and the question requirement should be: [1], therefore, the TRI Initialization is [[1], and the returned result is set to Tri [0] to meet the requirements;
2, the first layer loop is from 1 to I traversal, so it is difficult to control the data update, because the update of the J data to use the original tri row of the J-1 data, at this time the first J-1 data has been updated in the previous round;
3. To solve the problem in 2, modify the second-layer loop to traverse from I to 1 (because the first element is always 1 and does not need to be updated)
4. Function usage: range (START, end, step)
1 class solution: 2 # @ return a list of integers 3 def getrow (self, rowindex): 4 tri = [[1] 5 for I in range (1, rowindex + 1): 6 tri [0]. append (0) 7 for J in range (I, 0,-1): 8 if J = I: 9 tri [0] [J] = 110 else: 11 Tri [0] [J] + = tri [0] [J-1] 12 Return tri [0]
Leetcode: Pascal's triangle II