您的位置:首页 > 其它

Leetcode 119 Pascal's Triangle II

2016-12-12 18:49 405 查看
Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,

Return 
[1,3,3,1]
.
这个和一没啥区别= =
public class Solution {
public List<Integer> getRow(int rowIndex) {
ArrayList<Integer> result = new ArrayList<Integer>();
for(int i =0;i<rowIndex+1;i++){
result.add(0,1);
for(int j =1;j<result.size()-1;j++){//唯一要注意的这个减一= =
result.set(j,result.get(j)+result.get(j+1));
}
}
return result;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: