当前位置:网站首页>[leetcode notes] no118 Yanghui triangle

[leetcode notes] no118 Yanghui triangle

2022-06-24 00:05:00 Allow some artists to get rich first 1

This requires two layers for Circular questions it is to be noted that : Break the inherent thinking , Don't think about i=0 The time is 1 Instead, think in terms of computers The first 0 Start of bit instead of the first 1 position

class Solution {
    
    public List<List<Integer>> generate(int numRows) {
    
        List<List<Integer>> ret = new ArrayList<>();
        for(int i =0;i<numRows;i++){
    
            List<Integer> row = new ArrayList<>();
            for(int j =0;j<=i;j++){
    
                if(j==0||j==i){
    
                    row.add(1);
                }else{
    
                    row.add(ret.get(i-1).get(j)+ret.get(i-1).get(j-1));
                }
            }
            ret.add(row);
        }
        return ret;
    }
}
原网站

版权声明
本文为[Allow some artists to get rich first 1]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211703164722.html