给定一个非负索引 rowIndex
,返回「杨辉三角」的第 rowIndex
行。
在「杨辉三角」中,每个数是它左上方和右上方的数的和。
倒着进行就可以不出现覆盖问题
class Solution {
public List<Integer> getRow(int rowIndex) {
ArrayList<Integer> row =new ArrayList<>();
for(int i=0;i<= rowIndex;i++) {
row.add(1);
for(int j = i - 1; j > 0;j--)
row.set(j,row.get(j - 1) + row.get(j));
}
return row;
}
}