119. 杨辉三角 II(滚动数组优化的二维dp)

时间:2020-07-19 17:46:05   收藏:0   阅读:79

技术图片

 

class Solution {

    public List<Integer> getRow(int rowIndex) {
        Integer[] res = new Integer[rowIndex+1];
        Arrays.fill(res,1);
        for(int i = 1; i <= rowIndex; i++) {
            for(int j = i - 1; j > 0; j--) {
                res[j] = res[j-1] + res[j];
            }
        }
        return Arrays.asList(res);
    }
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!