class Solution {
public:
vector<vector<int>> vec;
vector<vector<int>> levelOrder(TreeNode* root) {
level_binary(root,0);
return vec;
}
void level_binary(TreeNode * root,int level){
if(root == NULL){ //递归终止条件
return ;
}
if(vec.size() == level) vec.resize(level + 1); //为什么要用resize
vec[level].push_back(root->val);
level_binary(root->left,level + 1);
level_binary(root->right,level + 1);
}
};
问题:为什么vector的二维数组的第一维为什么要用resize