Given an index k, return the kth row of the Pascal's triangle.
For example, given k = 3,
Return [1,3,3,1].
Note:
Could you optimize your algorithm to use only O(k) extra space?
vector<int> getRow(int rowIndex) { vector<int>result; vector<int>temp; if (rowIndex < 0)return result; temp.push_back(1); if (rowIndex == 0)return temp; for (int i = 0; i <= rowIndex;i++) { result.clear(); result.push_back(1); for (int j = 1; j < i; j++) { result.push_back(temp[j - 1] + temp[j]); } result.push_back(1); temp = result; } return result; }