要求:
用顺序表实现
class Solution {
public List<List<Integer>> generate(int numRows) {
//定义返回值
List<List<Integer>> ret = new ArrayList<>();
//把第零行赋值完毕
List<Integer> list0 = new ArrayList<>();
list0.add(1);
ret.add(list0);
//赋值中间部分
for (int i = 1; i <numRows ; i++) {
List<Integer> currentRow = new ArrayList<>();
currentRow.add(1);
List<Integer> previousRow = ret.get(i - 1);
for (int j = 1; j < i; j++) {
int x = previousRow.get(j - 1) + previousRow.get(j);
currentRow.add(x);
}
//赋值末尾部分
currentRow.add(1);
ret.add(currentRow);
}
return ret;
}
}