按层输出二叉树,广度优先。

    3
/ \
9 20
/ \
15 7
[
[15,7],
[9,20],
[3]
]
/**
* 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>> rres; void levelTree(TreeNode*root, int level){
if (root == NULL)
return;
if (level == rres.size()){
vector<int> res;
rres.push_back(res);
} rres[level].push_back(root->val);
levelTree(root->left,level+);
levelTree(root->right,level+);
} vector<vector<int>> levelOrderBottom(TreeNode* root) {
levelTree(root,);
//return reverse(rres.begin(),rres.end());
return vector<vector<int> >(rres.rbegin(), rres.rend());
}
};

【easy】107. Binary Tree Level Order Traversal II 按层输出二叉树的更多相关文章

  1. 102/107. Binary Tree Level Order Traversal/II

    原文题目: 102. Binary Tree Level Order Traversal 107. Binary Tree Level Order Traversal II 读题: 102. 层序遍历 ...

  2. 【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 ...

  3. 【一天一道LeetCode】#107. Binary Tree Level Order Traversal II

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...

  4. (二叉树 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 ...

  5. 【Leetcode】【Easy】Binary Tree Level Order Traversal II

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

  6. 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 ...

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

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

  8. [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 ...

  9. 剑指offer从上往下打印二叉树 、leetcode102. Binary Tree Level Order Traversal(即剑指把二叉树打印成多行、层序打印)、107. Binary Tree Level Order Traversal II 、103. Binary Tree Zigzag Level Order Traversal(剑指之字型打印)

    从上往下打印二叉树这个是不分行的,用一个队列就可以实现 class Solution { public: vector<int> PrintFromTopToBottom(TreeNode ...

随机推荐

  1. WordPress慢的八种解决方法(用排查法解决)

    WordPress的打开速度慢会影响到用户体验和关键词的稳定排名,WordPress为什么加载慢呢?其实很简单的,就是WordPress水土不服,用WordPress的大家都知道,WordPress是 ...

  2. (五)jdk8学习心得之默认方法

    五.默认方法 1. 使用方法:写在接口中,就是为了接口可以做一些事情. 2. 目的:有很多实现类,有一个公共的抽象方法,其实这些实现类实现该抽象方法的内容是完全一致的,完全没有必要都重新实现一遍.并且 ...

  3. lazyMan

    class Lazyman { constructor() { this.tasks = []; this.init(); } init() { const task = () => { con ...

  4. Excel vba中访问ASP.NET MVC项目,记录访问时间,文件名称

    每30秒连接一次服务器,连接成功单元格变绿色,连接失败变红色,状态单元格为17行,2列 1,打开excel文件,进入vba编辑器,新建一个modules模块,在里面先写一个每30秒执行一次ConnSe ...

  5. 仿 ELEMENTUI 实现一个简单的 Form 表单

    原文:仿 ElmentUI 实现一个 Form 表单 一.目标 ElementUI 中 Form 组件主要有以下 功能 / 模块: Form FormItem Input 表单验证 在这套组件中,有 ...

  6. Jetson TX1 compile pytorch issues

    1. c++: internal compiler error: Killed (program cc1plus) reason: memory out, need swapfile 2. NCCL ...

  7. IIS日志分析工具

    发现一个强大的图形化IIS日志分析工具:Log Parser Studio. 安装 需要先安装Log Parser下载地址:http://www.microsoft.com/en-us/downloa ...

  8. (最详细)小米Note 3的Usb调试模式在哪里打开的流程

    就在我们使用安卓手机链接PC的时候,或者使用的有些应用软件比如我们单位营销部门就在使用的应用软件引号精灵,之前使用的老版本就需要开启USB开发者调试模式下使用,现就在新版本不需要了,如果手机没有开启U ...

  9. tcpdump常用参数说明及常见操作

    tcpdump常用参数说明及常见操作 -a 将网络地址和广播地址转变成名字 -c 指定抓包的数量 -d 将匹配信息包的代码以人们能够理解的汇编格式给出 -dd 将匹配信息包的代码以c语言程序段的格式给 ...

  10. 命令级的python静态资源服务。

    python -m SimpleHTTPServer 在当前目录起python静态资源服务.