标签:lin var span solution ems oge question keep ast
https://leetcode.com/problems/pascals-triangle-ii/#/solutions
Given an index k, return the kth row of the Pascal‘s triangle.
For example, given k = 3,
Return [1,3,3,1]
.
Note:
Could you optimize your algorithm to use only O(k) extra space?
class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ # O(k) space, O(n^2) time res = [] for i in range(rowIndex+1): res.append(1) #range(start,end,step) for j in range(i,0,-1): if j == i: res[j] = 1 else: res[j] += res[j-1] return res
Note:
1 When the index j th element j equals to the row numer i, it means the j th element is the last element in the row.
标签:lin var span solution ems oge question keep ast
原文地址:http://www.cnblogs.com/prmlab/p/6995055.html