标签:
/** * 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>> levelOrderBottom(TreeNode* root) { vector<vector<int>> vv; vector<int> v; queue<TreeNode *>q; if(root == NULL) return vv; q.push(root); int h0=1; int h1; TreeNode * temp; while(!q.empty()){ h1=0; while(h0){ temp= q.front(); q.pop(); v.push_back(temp->val); if(temp->left){ q.push(temp->left); h1++; } if(temp->right){ q.push(temp->right); h1++; } h0--; } vv.push_back(v); v.clear(); h0=h1; } reverse(vv.begin(),vv.end()); return vv; } };
Binary Tree Level Order Traversal II
标签:
原文地址:http://www.cnblogs.com/julie-yang/p/4682872.html