List<List<> > the feeling of a nesting doll
ArrayList class: Dynamically modifiable arrays
I ++ makes no difference from ++ I
J starts at 1, which is the same as each row starts at the second element, and its value is equal to the sum of the two previous rows
public class Solution { /** * @param n: a Integer * @return: the first n-line Yang Hui's triangle */ public List<List<Integer>> calcYangHuisTriangle(int n) { List<List<Integer> > res = new ArrayList<>(); int i, j; if (n == 0) { return res; } for (i = 0; i < n; i++) { List<Integer> t = new ArrayList<Integer>(); t.add(1); for (j = 1; j < i; J ++) {//j starts at 1, equal to the second element in each line, and its value is equal to the sum of the two previous lines. } if (I > 0) {// The first element of each line is 1. } res.add(t); } return res; }}Copy the code