Deque and vector, easiest solution in O(K) extra space


#1
vector<int> Solution::getRow(int A) {
deque <int> x,y;

x.push_front(0);
x.push_back(1);
x.push_back(0);

for(int i=1;i<=A;i++) {
    for(int j=1;j<=i+1;j++) {
        y.push_back(x[j-1]+x[j]);
    }
    y.push_front(0);
    y.push_back(0);
    x.clear();
    x=y;
    y.clear();
}

vector <int> ans;
x.pop_front();
x.pop_back();
for(auto it:x)
ans.push_back(it);

return ans;

}