119. Pascal's Triangle II*
Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
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] """ result = *(rowIndex+1) result= 1 for i in range(1,rowIndex+1): for j in range(i,0,-1): result[j] +=result[j-1] return result
It is obvious that we should find the law of numbers in certain row of Pascal's Triangle.
According to materials online, the nth number in mth row is C(m,n-1).However, this method needs a lot of computation.