118. 杨辉三角

给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。

在杨辉三角中,每个数是它左上方和右上方的数的和。

示例:

输入: 5
输出:
[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]
class Solution {
    public List<List<Integer>> generate(int row) {
        List<List<Integer>> lists = new LinkedList<>();
        if(row == 0) return lists;
        List<Integer> list = new LinkedList<>();
        list.add(1);
        lists.add(list);
        for(int i = 0;i < row - 1;i++){
            List<Integer> temList = lists.get(i);
            List<Integer> tem = new ArrayList<>();
            tem.add(1);
            for(int j = 0;j < temList.size() - 1;j++){
                tem.add(temList.get(j) + temList.get(j + 1));
            }
            tem.add(1);
            lists.add(new ArrayList<>(tem));
        }
        return lists;
    }
}
一回生,二回熟
原文地址:https://www.cnblogs.com/zzytxl/p/12687128.html