class Solution {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
vector<vector<int>> res;
lOBhelp(res,root,0);
reverse(res.begin(),res.end());
return res;
}
void lOBhelp(vector<vector<int>> &res,TreeNode *r,int depth){
if(r==NULL) return;
if(depth+1>res.size()) res.resize(depth+1);
res[depth].push_back(r->val);
lOBhelp(res,r->left,depth+1);
lOBhelp(res,r->right,depth+1);
}
};
107. 二叉树的层次遍历 II
最新推荐文章于 2019-08-22 00:09:46 发布