Pascal's Triangle II
Problem: Pascal's Triangle II
To do this in O(k) extra space, we simply use one list to represent each row. We add the latter number to the former number and add 1 to the head of the list.
Code in Python:
class Solution(object):
def getRow(self, rowIndex):
"""
:type rowIndex: int
:rtype: List[int]
"""
res = [1]
for k in xrange(rowIndex):
for i in xrange(len(res)-1):
res[i] += res[i+1]
res = [1] + res
return res