【easy】107. Binary Tree Level Order Traversal II 按层输出二叉树
按层输出二叉树,广度优先。
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 按层输出二叉树的更多相关文章
- 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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源: htt ...
- (二叉树 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 ...
- 【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 ...
- 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 ...
- LeetCode 107 Binary Tree Level Order Traversal II(二叉树的层级顺序遍历2)(*)
翻译 给定一个二叉树,返回从下往上遍历经过的每一个节点的值. 从左往右,从叶子到节点. 比如: 给定的二叉树是 {3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 返回它从下 ...
- [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 ...
- 剑指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 ...
随机推荐
- 【keras】用tensorboard监视CNN每一层的输出
from keras.models import Sequential from keras.layers import Dense, Dropout from keras.layers import ...
- C#之委托与事件(转载)
委托 1. 委托是事件的基础,使用关键字delegate,通过委托与命名方法或匿名方法关联,可以实现委托的实例化.必须使用具有兼容返回类型和输入参数的方法或 lambda 表达式实例化委托. pri ...
- Virtual DOM 系列一:认识虚拟DOM
1. 什么是Virtual DOM? Virtual DOM(虚拟DOM)是指用JS模拟DOM结构.本质上来讲VD是一个JS对象,并且至少包含三个属性:tag(html标签),props(标签的属性, ...
- CnPack IDE 专家包(CnWizards)显示代引用单元列表
CnWizards_1.1.3.896
- docker基本使用
1.启动执行一次的容器 2.启动交互式容器 -i:告诉docker守护进程始终打开交互输入 -t:给容器分配一个伪tty终端 3.查看容器 docker ps:查看正在运行的容器 docker ps ...
- Mac 上的 GLFW 环境配置
背景:GLFW 一.下载和编译 从官网下载源代码包:http://www.glfw.org/download.html (我下载的是 github 仓库上的) 按官方指南编译.总结如下: cd glf ...
- ADRC-active disturbance rejection control-自抗扰控制器
ADRC自抗扰控制基本思想要点: 1.标准型与总扰动,扩张状态与扰动整体辨识,微分信号生成与安排过渡过程以及扰动的消减与控制量产生. ADRC主要构成: 1)跟踪微分器(TD)---the track ...
- LeetCode--11_974_Subarray_Sums_Divisible_by_K
题目链接:点击这里 public static int subarraysDivByK(int[] A, int K) { int ans = 0,sum = 0; int[] B = new int ...
- Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array(动态规划.递推)
传送门 题意: 给你一个包含 n 个元素的序列 a[]: 定义序列 a[] 的 beauty 为序列 a[] 的连续区间的加和最大值,如果全为负数,则 beauty = 0: 例如: a[] = {1 ...
- Hadoop记录-queue使用率
#!/bin/sh ip=xxx port=8088 export HADOOP_HOME=/app/hadoop/bin rmstate1=$($HADOOP_HOME/yarn rmadmin - ...