标签:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
private:
int maxDep;
vector<vector<int>> res;
public:
void traversal(int dep, TreeNode *root) {
if(root == NULL)
return;
if(res.size() < dep + 1) {
vector<int> tmp;
tmp.push_back(root->val);
res.push_back(tmp);
} else {
res[dep].push_back(root->val);
}
traversal(dep + 1, root->left);
traversal(dep + 1, root->right);
}
vector<vector<int>> levelOrderBottom(TreeNode* root) {
traversal(0, root);
return vector<vector<int>>(res.rbegin(), res.rend());
}
};
版权声明:本文为博主原创文章,未经博主允许不得转载。
Binary Tree Level Order Traversal II
标签:
原文地址:http://blog.csdn.net/guanzhongshan/article/details/46744157