Pascal's Triangle II

2018-03-01 11:18:05来源:oschina作者:厉力文武人点击

分享

Given an indexk, return thekthrow of the Pascal's triangle.


For example, givenk= 3, Return[1,3,3,1].


class Solution {
public List getRow(int rowIndex) {
List row = new ArrayList<>();

row.add(1);
if (rowIndex > 0) {
for (int i = 1; i <= rowIndex; ++ i) {
List tmp = new ArrayList<>();

tmp.add(row.get(0));
for (int j = 1; j < i; ++ j) {
tmp.add(row.get(j) + row.get(j - 1));
}
tmp.add(row.get(0));
row = tmp;
}
}

return row;
}
}

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台