Daily Leetcode Brush Questions Primary Algorithm-Yang Hui Triangle

Subject requirements:

Insert picture description here

Lie deduction problem solution:

Insert picture description here

Code

import java.util.ArrayList;
import java.util.List;

/**
 * @program: mydemo
 * @description: this is a class
 * @author: Mr.zeng
 * @create: 2021-03-01 10:09
 **/
public class Solution39 {
    
    
    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-1)+ret.get(i-1).get(j));
                }
            }
            ret.add(row);
        }
        return ret;
    }
}

Guess you like

Origin blog.csdn.net/weixin_42292697/article/details/114255402