class Solution:
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
# method one
# row = [1]
# for i in range(1,rowIndex+1):
# row = list(map( lambda x,y : x+y , row + [0] , [0] + row ))
# return row
# method two 老土的方法,但有效,不用借助高等函数map()
res = [1]
for i in range(1, rowIndex+1):
res = [1] + [res[i] + res[i + 1] for i in range(len(res) - 1)] + [1]
return res
leetcode 119. Pascal's Triangle II(杨辉三角II) python3 两种思路(老土但高效的list拼接 / 优雅的map()方法)
猜你喜欢
转载自blog.csdn.net/huhehaotechangsha/article/details/80542900
今日推荐
周排行