/**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param root: A tree
* @return: buttom-up level order a list of lists of integer
*/
vector<vector<int>> levelOrderBottom(TreeNode * root) {
vector<vector<int>> ans,ans1;
vector<TreeNode *> node;
vector<int> layernum;
vector<int> layer;
int front=0;
if(root==NULL) return ans1;
node.push_back(root);
layernum.push_back(0);
while(node.size()-front>0){
if(front!=0&&layernum[front]!=layernum[front-1]){
ans.push_back(layer);
layer.clear();
}
layer.push_back
LintCode 70 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历)
最新推荐文章于 2020-12-13 17:53:08 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)