I got an answer with O(1) space.

The idea is that, for n-th row, the value at col j is (n,j) (I mean n choose j here).

And we have (n,j) = (n, j-1) * (n-j+1) / j.

Then we can have the solution as below:

```
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> res;
if (rowIndex >= 0) {
res.push_back(1);
}
for (int j = 1; j <= rowIndex; j++) {
res.push_back((double)res.back() * (double)(rowIndex - j + 1) / (double)j);
}
return res;
}
};
```

One further question I'm wondering is, is it possible eliminate type cast here (which was to avoid overflow)?