leetcode_119

Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.

Note that the row index starts from 0.

In Pascal's triangle, each number is the sum of the two numbers directly above it.

Follow up:

Could you optimize your algorithm to use only O(k) extra space?

Solutions

  1. dynamic programming

  2. To save the space used for recording the overriten pascal number in the last layer, we calculate from the end to the beginning.

  3. Only a half of a certain layer needs to be calculated since numbers in each layer are symmetric.

  1. math formula

Last updated

Was this helpful?