# Question

Formatted question description: https://leetcode.ca/all/119.html

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?

@tag-array


# Algorithm

Except for the first and last numbers, the other numbers are the sum of the left and right values in the previous line. Then we only need two for loops.

Except for the first number being 1, the following numbers are the sum of the value of the previous loop plus the value of the previous position, and keep updating the value of each position. You can get the number in the nth row.

Java