您的位置:首页 > 其它

Leetcode 119. Pascal's Triangle II

2016-12-20 06:57 513 查看
/**
*        1
*      1   1
*    1   2   1
*   1  3   3   1
* 1  4   6   4  1
*/
public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> pt = new ArrayList<Integer>();

pt.add(1);

for (int i=1; i<=rowIndex; i++) {
// from end of the list to the beginning, make sure that pt[j] is never changed*
for (int j=i-1; j>0; j--)
pt.set(j, pt.get(j)+pt.get(j-1));
pt.add(1);
}
return pt;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: