119. Pascal's Triangle II
网址:https://leetcode.com/problems/pascals-triangle-ii/description/
代码:
class Solution:
def getRow(self, rowIndex):
_list = [1]
if rowIndex == 0:
return _list
if rowIndex > 0:
_list = [1]
for index in range(rowIndex + 1):
last_list = _list
_list = [1]
for j in range(index-1):
_list.append(last_list[j] + last_list[j+1])
_list.append(1)
return _list
思路:先定义一个初始数组_list为[1],然后用两层循环一步步更新_list中的内容,使用last_list来记录上一层的数组内容,最后返回_list
提交情况: