/**
* 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 {
Public
vector<vector<int> > result;
void Solve (treenode*root,int dep)
{
if (root==null)
return;
if (Dep==result.size ())//There is no element in the current result, it is the structure of a two-layer vector
{vector<int>temp;
Result.push_back (temp); So you have to push a vector container in. If it is on the same level as the previous node, only the first node is added to the vector container, followed by a direct add
}
Result[dep].push_back (root->val);//Add elements to the current container
if (root->left!=null)
Solve (root->left,dep+1);
if (root->right!=null)
Solve (root->right,dep+1);
}
Vector<vector<int>> levelorderbottom (treenode* root) {
Solve (root,0);
Reverse (Result.begin (), Result.end ());
return result;
Return vector<vector<int>> (Result.rbegin (), Result.rend ());
}
};
Binary Tree level Order traversal II