转换成一个二维数组,即可发现规律
import java.util.ArrayList;
import java.util.List;
public class Problem_118_Pascals_Triangle {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> rows = new ArrayList<>();
for (int row = 0; row < numRows; row++) {
List<Integer> oneRow = new ArrayList<>();
for (int col = 0; col <= row; col++) {//对角线左边部分
if(col == 0 || col == numRows) oneRow.add(1);
else {
List<Integer> preRow = rows.get(row - 1);
oneRow.add(preRow.get(col - 1) + preRow.get(col));
}
}
rows.add(oneRow);
}
return rows;
}
}