I am getting segmentation fault for this trivial solution. I am not able to figure out where is the problem.
vector<int> Solution::getRow(int A) {
vector<vector <int>> res(A);
vector<int> ans;
for(int i=0; i<=A; i++)
for(int j=0; j<=i; j++)
res[i].push_back(1);
for(int i=2; i<=A; i++)
for(int j=1; j<i; j++)
res[i][j]= res[i-1][j] + res[i-1][j-1];
for(int i=0; i<=A; i++)
ans[i] = res[A][i];
return ans;
// OR
// return res[A];
}
Thank you for your time and help.