Binary Tree Level Order Traversal II
/**
* 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=;
int h1;
TreeNode * temp;
while(!q.empty()){
h1=;
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的更多相关文章
- 35. Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal OJ: https://oj.leetcode.com/problems/binary-tree-level-order-trave ...
- Binary Tree Level Order Traversal,Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal Total Accepted: 79463 Total Submissions: 259292 Difficulty: Easy G ...
- LeetCode之“树”:Binary Tree Level Order Traversal && Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal 题目链接 题目要求: Given a binary tree, return the level order traversal o ...
- 102/107. Binary Tree Level Order Traversal/II
原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...
- 【LeetCode】107. Binary Tree Level Order Traversal II (2 solutions)
Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order traversal ...
- LeetCode_107. Binary Tree Level Order Traversal II
107. Binary Tree Level Order Traversal II Easy Given a binary tree, return the bottom-up level order ...
- 63. Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal II My Submissions QuestionEditorial Solution Total Accepted: 79742 ...
- [LeetCode] Binary Tree Level Order Traversal II 二叉树层序遍历之二
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- 【Binary Tree Level Order Traversal II 】cpp
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...
- Binary Tree Level Order Traversal II 解题思路
思路: 与Binary Tree Level Order Traversal I 几乎一样.只是最后将结果存放在栈里,然后在栈里再传给向量即可. 再次总结思路: 两个queue,先把第一个放进q1,循 ...
随机推荐
- PHP受保护的类和私有类什么区别
受保护的继承后可以访问,私有的只能在该类中访问,不会被继承访问class Man{ protected $name='lee';//受保护 private $age=123;//私有 function ...
- [BS] 小知识点总结-01
1. UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MainTitle&quo ...
- 线性四叉树十进制Morton码计算示例
线性四叉树十进制Morton码计算,具体算法描述龚健雅<地理信息系统基础>P108
- Python_技巧系列
1 print()中利用 \ 实现美观 2 利用列表对多个变量进行赋值 3 变量存储的是什么 3.1 对于不可变的数据类型的值,变量存储的是引用(如:列表.字典):所以不可变变量间的赋值是引用赋值 3 ...
- NSString的截取
// // main.m // 02-字符串的获取 // // Created by apple on 14-3-20. // Copyright (c) 2014年 apple. All r ...
- 设计模式之 -- 单例模式(Singleton)
单例模式是一种常用的软件设计模式,通过单例模式可以保证系统中一个类只有一个实例而且该实例易于外界访问. 使用说明 1.使用时机 在某些系统中某些对象最多只能存在一个,例如Windows中只能打开一个 ...
- canvas学习之圆周运动
html部分 ...... <body> <canvas id="myCanvas" width="400" height="400 ...
- 不等高cell搭建(二)
一.commentView模块搭建 commentView样式分为两种 1.xib搭建界面 1.1 因为评论的样式大体上一样,我们可以用同一个xib来处理 1.2 最热评论 用 ...
- 初始化 Gradle 工程目录(转自: 隔叶黄莺 Unmi Blog)
最近重新在 Eclipse 中打开旧的 Maven 项目,总有些什么错误,备受折磨.期间试手了 Ant+Ivy, 现今试用了下 Gradle,感觉不错,它应该才是我真想要的,Maven 差不多该扔到一 ...
- java List 简单使用
Student类 class Student{ String name; String pwd; public Student(){} public Student(String name, Stri ...