题目:
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 sumunms(self,nums):
sans = [1]
for i in range(1,len(nums)):
sans.append(nums[i]+nums[i-1])
sans.append(1)
return sans
def getRow(self, numRows):
"""
:type numRows: int
:rtype: List[List[int]]
"""
if numRows==0:
return [1]
if numRows==1:
return [1,1]
ans = [1,1]
while numRows>1:
ans = self.sumunms(ans)
numRows-=1
return ans
a = Solution()
print a.getRow(2)