public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> list = new ArrayList<Integer>();
if (rowIndex < 0)
return list;
for (int i = 0; i < rowIndex + 1; i++) {
list.add(0, 1); // insert 1 at position 0
for (int j = 1; j < list.size() - 1; j++) {
list.set(j, list.get(j) + list.get(j + 1));
}
}
return list;
}
}
Leetcode 119. Pascal's Triangle II
最新推荐文章于 2021-09-05 15:16:01 发布