
1 |
class Solution { |
- 注意点:vector创建二维数组的时候, vector
> arr(numRows); arr后面一定要加上长度,用小括号扩起。
- 递归法会超时,所以考虑其他方法。从后往前遍历
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> arr;
arr.resize(rowIndex+1);
arr[0]=1;
if(rowIndex == 0){
return arr ;
}
for(int i=0;i<rowIndex;i++){
arr[rowIndex]=1;
for(int k = rowIndex-1; k > 0; --k){
arr[k] = arr[k] + arr[k-1];
}
arr[0]=1;
}
return arr;
}
};




近期评论