相似题目:

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. pyinstaller打包总结

    建立py打包文件 if __name__ == '__main__': from PyInstaller.__main__ import run #opts=['music.py','--path=C ...

  2. Django设置 DEBUG=False后静态文件无法加载

    修改setting.py STATIC_URL = '/static/' STATIC_ROOT = 'static' ## 新增行 STATICFILES_DIRS = [ os.path.join ...

  3. oracle分页查询按日期排序失败问题

    今天对已经上线的代码进行测试,结果发现分页是失效的,一度怀疑是前台页面分页失效,排查后发现是分页sql有问题,分页sql按日期排序,导致分页失败. 按日期排序,会造成相同的数据重复出现. 解决方案:在 ...

  4. laravel 的lnmp 的配置

    装了lnmp后,一般用 lnmp vhost add 添加网站 一般 只用重写和ssl功能 再发laravel官方的配置 server { listen 80; server_name example ...

  5. html 自动跳转页面

    三种简单的html网页自动跳转方法,可以让你在打开一个html网页时自动跳转到其它的页面. 方法一. <html> <head> <meta http-equiv=&qu ...

  6. webpack 热更新

    1.安装webpack npm install webpack -g  //全局安装 npm install webpack --save-dev  //开发环境 2.使用webpack 创建一个we ...

  7. 【转】h5页面audio不自动播放问题

    1.audio:html5音频标签 <audio loop src="/photo/aa.mp3" id="audio" autoplay preload ...

  8. Vue使用 weui picker 弹出框不消失

    前言 最近使用 weui 里面的 datepicker 组件的时候遇到了一个问题: 弹出来 选择年月日的框之后,直接点击导航上的“返回” 按钮,picker 选框不消失,也就是弹出框不消失 weui. ...

  9. python连接 MySQ 数据库

    python 是目前比较流行的语言,所以学习一下 首先需要 安装MySQL-python驱动 下载地址:http://dev.mysql.com/downloads/connector/python/ ...

  10. mysql8.0.17复制搭建及其gtid的1062和1032异常

    mysql8.0.17复制搭建及其gtid的1062和1032异常 参考资料: https://blog.csdn.net/wzy0623/article/details/91982743https: ...