标签:
return tmpLarge.push_back(tmp);
不等价于
tmpLarge.push_back(tmp);
return tmpLarge;
因为push_back()返回值类型为void,而后者返回tmpLarge的类型。
代码如下:
class Solution {
public:
vector<vector<int>> generate(int numRows) {
if(numRows == 0) {
vector<vector<int>> tmpLarge;
return tmpLarge;
}
if(numRows == 1) {
vector<int> tmp;
vector<vector<int>> tmpLarge;
tmp.push_back(1);
//"return tmpLarge.push_back(tmp);" is error
tmpLarge.push_back(tmp);
return tmpLarge;
}
vector<vector<int> > smallResult = generate(numRows - 1);
vector<int> tmp;
smallResult.push_back(tmp);
smallResult[numRows - 1].push_back(1);
for(int i = 0; i <= numRows - 3; i++) {
smallResult[numRows - 1].push_back(smallResult[numRows - 2][i] + smallResult[numRows - 2][i + 1]);
}
smallResult[numRows - 1].push_back(1);
return smallResult;
}
};
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/guanzhongshan/article/details/46755093