LeetCode 数据结构—杨辉三角 II

 

 这道题属于Easy题,要求到目标行数,只需要一直递归上一行的内容即可。

    public List<Integer> getRow(int rowIndex) {
        List<Integer> res=new LinkedList<>();
        if(rowIndex==0)
        {
            res.add(1);
             return res;
        }
        List<Integer> lastRow=getRow(rowIndex-1);
        res.add(1);
        for(int i=0;i<lastRow.size()-1;i++)
        {
            res.add(lastRow.get(i)+lastRow.get(i+1));
        }
        res.add(1);
        return res;
    }

 

posted @ 2021-10-19 20:03  毅毅毅毅毅  阅读(34)  评论(0)    收藏  举报