关于C++中stl中的vector二维动态数组问题

翻身的咸鱼ing 2020-03-27 01:31:08
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); vec[level].push_back(root->val); level_binary(root->left,level + 1); level_binary(root->right,level + 1); } }; 我想问为什么vector的二维数组的第一维为什么要用resize
...全文
53 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧