LeetCode-119.杨辉三角II(相关话题:数组)

Java代码:

class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> res = new ArrayList<>(rowIndex+1);
        for(int i = 0; i <= rowIndex; i++){
            res.add(1);
            for(int j = i-1; j > 0; j--){
                res.set(j, res.get(j) + res.get(j-1));
            }
        }

        return res;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_38823568/article/details/83187156