力扣119. 杨辉三角 II

原题

 1 class Solution:
 2     def getRow(self, rowIndex: int) -> List[int]:
 3         ans = [1]
 4         for i in range(rowIndex):
 5             # tmp = [1]
 6             # for j in range(1,len(ans)):
 7             #     tmp.append(ans[j-1] + ans[j])
 8             # tmp.append(1)
 9             # ans = tmp
10             j = len(ans)-1
11             while j > 0:
12                 ans[j] += ans[j - 1]
13                 j -= 1
14             ans.append(1)
15         return ans

 

posted @ 2021-02-12 11:40  凝视深空  阅读(67)  评论(0编辑  收藏  举报