119 Pascal's Triangle II
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?
The Idea: Pascal's Triangle can be built off the previous case, so we can iterate to the kth row dynammically. Add 0's to the edges to make things easier and for clean. We can cut these off at the end.
Complexity: O(row_index * (sum i = 1 to row_index (length(root))) time and constant space
Last updated