1. 程式人生 > >leetcode 119. Pascal's Triangle II(楊輝三角II) python3 兩種思路(老土但高效的list拼接 / 優雅的map()方法)

leetcode 119. Pascal's Triangle II(楊輝三角II) python3 兩種思路(老土但高效的list拼接 / 優雅的map()方法)

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