题目来源【Leetcode】
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?
这道题就是显示杨辉三角行的某一行;
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<vector<int>>tr(rowIndex+1);
for(int i = 0; i <= rowIndex; i++){
tr[i].resize(i+1);
for(int j = 0; j < i+1; j++){
if(j == 0 || j == i) tr[i][j] = 1;
else tr[i][j] = tr[i-1][j-1]+tr[i-1][j];
}
}
return tr[rowIndex];
}
};