119. Pascal's Triangle II

这个题以前做的不对,以前实际上是在期间建立templist了。

要用list.set(i,j)来做才满足O(k)

public class Solution {
    public List<Integer> getRow(int rowIndex) {
        List<Integer> res = new ArrayList<>();
        
        for (int i = 0; i <= rowIndex; i++) {
            res.add(0,1);
            for (int j = 1; j < i; j++) {
                res.set(j, res.get(j) + res.get(j+1));
            }
        }
        
        return res;
    }
}
posted @ 2016-11-05 05:10  哇呀呀..生气啦~  阅读(74)  评论(0)    收藏  举报