classSolution { public: vector<int> getRow(int rowIndex){ int k = rowIndex; if(k == 0) returnvector<int>({1}); if(k == 1) returnvector<int>({1,1}); vector<int> vc({1,2,1}); for(int i = 2; i < k; ++i) { int tmp_jMinus1 = vc[0]; //copy to prevent being covered int tmp_j = vc[1]; for(int j = 1; j < i; ++j) { int tmp_val = tmp_jMinus1 + tmp_j; tmp_jMinus1 = tmp_j; tmp_j = vc[j+1]; //copy to prevent being covered vc[j] = tmp_val; //covering the value } vc.back() = tmp_jMinus1 + tmp_j; //change the second last value vc.push_back(1); //add the last one } return vc; } };