Tuesday, October 14, 2014

Pascal's Triangle II

Problem

Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,
Return [1,3,3,1].

Idea

这个题目要求memory O(k)。所以只能用1维数组来做。发现row[i] = row[i]+row[i-1] 左边是下一行的row[i],右边是上一行的row[i]和row[i-1]

Solution


No comments:

Post a Comment