同118思路解题方法时间复杂度为O(n2)的代码
class Solution {
public List<Integer> getRow(int rowIndex) {
//初始化一个二维数组
List<List<Integer>> triangle = new ArrayList<>();
//添加第0行数据,设置第0个数为1
triangle.add(new ArrayList<Integer>());
triangle.get(0).add(1);
for(int i = 1;i < rowIndex+1;i++){
//新建列表,添加首位数字为1
triangle.add(new ArrayList<>());
triangle.get(i).add(1);
for(int j = 1;j<i;j++){
triangle.get(i).add(triangle.get(i-1).get(j-1)+triangle.get(i-1).get(j));
}
triangle.get(i).add(1);
}
return triangle.get(rowIndex);
}
}
