void lobHelp(vector<vector<int>> &res,unsigned int lev,TreeNode *r) { if(r==NULL) return; if(lev+1>res.size()) { res.push_back(vector<int>()); } res[lev].push_back(r->val); lobHelp(res,lev+1,r->left); lobHelp(res,lev+1,r->right); } vector<vector<int>> levelOrderBottom(TreeNode* root) { vector<vector<int>> res; lobHelp(res,0,root); int n=res.size(); for(int i=0;i<n/2;++i) { swap(res[i],res[n-1-i]); } return res; }
转载于:https://www.cnblogs.com/xLester/p/7570281.html