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]
.
思路:
简单的数学推理即可
我的代码:
public class Solution { public List<Integer> getRow(int rowIndex) { List<Integer> rst = new ArrayList<Integer>(); if(rowIndex < 0) return rst; rst.add(1); for(int i = 1; i <= rowIndex; i++) { for(int j = rst.size() - 1; j > 0; j--) { rst.set(j, rst.get(j) + rst.get(j - 1)); } rst.add(1); } return rst; } }