This is not harder than the last problem, except that it limits the space to O(k).
Solution:
# T:O(n^2) S:O(k)
class Solution:
# @return a list of integers
def getRow(self, rowIndex):
result = [1]
for i in range(1, rowIndex + 1):
result = [1] + [result[j - 1] + result[j] for j in range(1, i)] + [1]
return result
Run Time: 36 ms
No comments:
Post a Comment