相似题目:

102 103 107

 /**
* 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) {
if(root==NULL) return {};
queue<TreeNode*> q;
TreeNode* front;
q.push(root);
vector<vector<int>> res;
while(!q.empty()){
vector<int> onelevel;
for(int i=q.size();i>;i--){
front=q.front();
q.pop();
if(front->left)
q.push(front->left);
if(front->right)
q.push(front->right);
onelevel.push_back(front->val);
}
res.push_back(onelevel);
}
reverse(res.begin(),res.end());
return res;
}
};

其实这个解答只是reverse 了一下,算是投机取巧吧,之后写个从叶节点遍历的。

leetcode 107.Binary Tree Level Order Traversal II 二叉树的层次遍历 II的更多相关文章

  1. [LintCode] Binary Tree Level Order Traversal(二叉树的层次遍历)

    描述 给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问) 样例 给一棵二叉树 {3,9,20,#,#,15,7} : 3 / \ 9 20 / \ 15 7 返回他的分层遍历结果: [ [3] ...

  2. Leetcode 102. Binary Tree Level Order Traversal(二叉树的层序遍历)

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  3. LeetCode 107 Binary Tree Level Order Traversal II(二叉树的层级顺序遍历2)(*)

    翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下 ...

  4. Java for LeetCode 107 Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  5. [LeetCode] 107. Binary Tree Level Order Traversal II 二叉树层序遍历 II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  6. (二叉树 BFS) leetcode 107. Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  7. LeetCode 107. Binary Tree Level Order Traversal II (二叉树阶层顺序遍历之二)

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  8. leetcode 107 Binary Tree Level Order Traversal II ----- java

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  9. LeetCode 107. Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  10. Java [Leetcode 107]Binary Tree Level Order Traversal II

    题目描述: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, fro ...

随机推荐

  1. vue中如何引入css文件

    两种方式引入css文件,一种是直接在main.js中引入(也可以在其他的.vue文件中的<script></script>标签中),即下面这种写法: import 'eleme ...

  2. 84. Largest Rectangle in Histogram (JAVA)

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  3. IIS下设置跨域访问问题--Access-Control-Allow-Origin 站点跨域请求的问题

    背景: 最近 开发中遇到新需求,把公司的OA系统迁移一套到小程序上面去 有些功能的信息是在小程序 查看 但是文件是在pc端上传的 例如:领导在外出办公 使用小程序查看xxxx.pdf文件  这个时候就 ...

  4. 电脑系统win7和samba服务器连接不上解决办法

    1.修改本地安全策略运行secpol.msc打开“本地安全策略”窗体,依次点开“本地策略”->“安全选项”,修改“网络安全: LAN 管理器身份验证级别”的值为“发送 LM 和 NTLM – 如 ...

  5. 自动化监控软件之zabbix安装

    自动化监控系统 cacti : 基于snmp(简单的网络管理协议)协议的监控软件,强大的绘图软件 缺点: 自带的监控模板比较少,不能默认 自带监控报警功能(只能自己去官网下载模板) Nagios: 插 ...

  6. jquery在线引用地址大全 全部来自官网

    谷歌的就算了,容易被屏蔽,下面都是官方原版的 最新版本 <script src="http://code.jquery.com/jquery-latest.js">&l ...

  7. zabbix服务的布置(脚本)

    一,服务端配置 #!/bin/bash#clsn #设置解析 注意:网络条件较好时,可以不用自建yum源# echo '10.0.0.1 mirrors.aliyuncs.com mirrors.al ...

  8. 关于3.1 jmu-Java-03面向对象基础-01-构造函数与toString (3 分)

    PTA显示Compiler did not create the expected binary 不知所措   package nn;  import java.util.Scanner;       ...

  9. 多线程使用@Async注解创建多线程,自定义线程池

    转载自博客https://www.jianshu.com/p/7ac04a501eba

  10. 解决sonar的ES无法启动问题

    单独启动SonarQube自带的ElasticSearch报错 错误1.8:++PrintGCDetails找不到主类等 解决方法: 打开sonar/elasticsearch/config文件夹 修 ...