It takes a different approach than others and uses Pascal's theorem to formulate the answer.

```
public List<Integer> getRow(int rowIndex) {
List<Integer> rows = new ArrayList(rowIndex+1);
for(int i=0;i<rowIndex+1;i++) {
rows.add(ncr(rowIndex,i));
}
return rows;
}
private int ncr(int n, int k) {
int m= Math.min(n-k, k);
long cnm= 1;
for (int i= n-m+1, j= 1; i <= n; i++, j++) {
cnm*= i;
cnm/= j;
}
return (int)cnm;
}
```