# leetcode 107 Binary Tree Level Order Traversal II(最底层往上依次输出二叉树每一个node的val)

Posted by 111qqz on Monday, February 20, 2017

## TOC

leetcode107

``````/* ***********************************************
Author :111qqz
Created Time :2017年02月20日 星期一 19时21分51秒
File Name :107.cpp
************************************************ */
/**

* 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>>res;
vector<int>tmp[1500];
int mx_level = 0 ;
void dfs( TreeNode* root,int level)
{
//  cout<<"level:"<<level<<endl;
mx_level = max(mx_level,level);
if (root->left!=NULL)
{
tmp[level].push_back(root->left->val);
dfs(root->left,level+1);
}
if (root->right!=NULL)
{
tmp[level].push_back(root->right->val);
dfs(root->right,level+1);
}
}
vector<vector<int>> levelOrderBottom(TreeNode* root) {
if (root==NULL) return res;
tmp[0].push_back(root->val);
dfs(root,1);
for ( int i = mx_level;  i>= 0 ; i--)if (!tmp[i].empty()) res.push_back(tmp[i]);
return res;
}

};
``````