Closed congr closed 5 years ago
use only O(k) extra space
class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> list = new ArrayList();
for (int i = 0; i <= rowIndex; i++) {
list.add(0, 1); // !!!!!!!!!!! 11 -> (1)11 => 121
for (int j = 1; j < i; j++) {
list.set(j, list.get(j) + list.get(j+1)); // !!
}
System.out.println(list);
}
return list;
}
}
https://leetcode.com/problems/pascals-triangle-ii/