Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return
Return
[1,3,3,1]
.
Note:
Could you optimize your algorithm to use only O(k) extra space?
Could you optimize your algorithm to use only O(k) extra space?
----------------------------
Note: O(k) means we can only use in-place way:
method: from right to left
eg.:
1 4 6 4 1 0 previous line
0 0 0 0 0 1 now calculate in place from right to left
0 0 0 0 5 1
0 0 0 10 5 1
0 0 10 10 5 1
0 5 10 10 5 1
1 5 10 10 5 1
No comments:
Post a Comment