public class Solution {
public ArrayList<Integer> getRow(int rowIndex) {
ArrayList<Integer> res = new ArrayList<Integer> (rowIndex);
for (int i=0; i<=rowIndex; i++) {
res.add(i, 0);
}
res.set(0, 1);
for (int i=1; i<=rowIndex; i++) {
res.set(i, 1);
for (int j=i-1; j>0; j--) {
res.set(j, res.get(j)+res.get(j-1));
}
}
return res;
}
}
[1]
回复删除[1 1]
[1 1 1]-->[1 2 1]
[1 2 1 1]-->[1 3 3 1]
[1 3 3 1 1]->[1 4 6 4 1]
backwards.
This method is really brilliant.