
java
class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> currentRow = new ArrayList<>();
currentRow.add(1);
//依次替换上一行
for(int i = 1;i <= rowIndex;i++){
//先在结尾放1
currentRow.add(1);
//设置中间数字的值
for(int j = i - 1;j > 0;j--){
currentRow.set(j,currentRow.get(j) + currentRow.get(j - 1));
}
}
return currentRow;
}
}
中间数字=自己+左边数字,只能从后往前算,如果从前往后算,前面数字先计算完成后,后面数字再计算这时他的左邻居相当于是变了数字的。