The idea is:

Use only one array or array list with space of rowIndex + 1, fill them all with 1. Then loop from 2 to rowIndex, calculate from end back to middle (half), mirror it to first half. And we can reuse same array to calculate next row since the calculation will use (current position) and (current position - 1) data.

```
public class Solution {
public ArrayList<Integer> getRow(int rowIndex) {
if (rowIndex < 0) {
return null;
}
ArrayList<Integer> data = new ArrayList<>(rowIndex + 1);
for (int i = 0; i < rowIndex + 1; i ++) {
data.add(1);
}
if (rowIndex < 2) {
return data;
}
for (int i = 2; i <= rowIndex; i ++) {
fillpt(data, i);
}
return data;
}
private void fillpt(ArrayList<Integer> data, int row) {
int half = row - (row / 2);
for (int i = row - 1; i >= half; i--) {
data.set(i, data.get(i) + data.get(i - 1));
}
for (int i = row - 1; i >= half; i --) {
data.set(row - i, data.get(i));
}
}
```