码迷,mamicode.com
首页 > 其他好文 > 详细

119. Pascal's Triangle II

时间:2016-05-20 13:17:10      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

    /*
     * 119. Pascal‘s Triangle II 
     * 12.6 by Mingyang 
     * 注意list.set(index,value)是改变某一个index的value
     * 从后面往前加
     */
    public List<Integer> getRow(int rowIndex) {
        List<Integer> res = new ArrayList<Integer>();
        res.add(1);
        if (rowIndex == 0)
            return res;
        for (int j = 1; j < rowIndex + 1; j++) {
            res.add(1);
            for (int i = j - 1; i > 0; i--) {
                res.set(i, res.get(i - 1) + res.get(i));
            }
        }
        return res;
    }

 

119. Pascal's Triangle II

标签:

原文地址:http://www.cnblogs.com/zmyvszk/p/5511563.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!