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:
# @return a list of integers
def getRow(self, rowIndex):
result = []
for i in range(rowIndex+1): result.append(self.func(rowIndex) / (self.func(i) * self.func(rowIndex-i)))
return result
def func(self, k):
sum = 1
for i in range(1, k+1):
sum = sum * i
return sum