LeetCode 102. Binary Tree Level Order Traversal 动态演示
按层遍历树,要用到queue
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>> ret;
//ahd(root)
//a(ret)
queue<TreeNode*> que;
//a(que)
if(!root)
return ret;
que.push(root);
//dsp
while(!que.empty()){
int n=que.size();
vector<int> line;
//a(line)
while(n-->){
auto cur=que.front(); que.pop();
line.push_back(cur->val);
//a(cur)
//lk("root",cur)
if(cur->left) que.push(cur->left);
if(cur->right) que.push(cur->right);
//dsp
}
ret.push_back(line);
//dsp
}
return ret;
}
};
程序动态运行过程:http://simpledsp.com/FS/Html/lc102.html
LeetCode 102. Binary Tree Level Order Traversal 动态演示的更多相关文章
- [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, ...
- 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, ...
- leetcode 102 Binary Tree Level Order Traversal ----- java
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- Java [Leetcode 102]Binary Tree Level Order Traversal
题目描述: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ...
- 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, ...
- LeetCode 102. Binary Tree Level Order Traversal 二叉树的层次遍历 C++
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- Java for 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, ...
- leetcode 102 Binary Tree Level Order Traversal(DFS||BFS)
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- Leetcode 102 Binary Tree Level Order Traversal 二叉树+BFS
二叉树的层次遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * ...
随机推荐
- CentnOS7安装Nginx“No package available”
Nginx相对Apache有轻量级,简洁的优点,算得上Apache的优秀替代品了,但是由于Nginx不在yum的官方源中,因此安装时总会出现失败的现象,只需: yum install epel-rel ...
- MySQL-第六篇DML语句
1.DML主要操作数据表里的数据,主要完成3个任务: 1>insert:插入数据.格式:insert into ... 2>delete:删除数据.格式:delete from ... 3 ...
- 我心中的ASP.NET Core 新核心对象WebHost(一)
以本系列文章向Fish 前辈的那篇我心中的ASP.NET 核心对象致敬.(虽然不知道前辈现在在干什么).一晃就6年过去了,那首 郝云 的<回到那一天>怎么唱来着? 时光一晃,你就三十了. ...
- 攻防世界--crackme
测试文件:https://adworld.xctf.org.cn/media/task/attachments/088c3bd10de44fa988a3601dc5585da8.exe 1.准备 获取 ...
- 2018-8-10-win10-uwp-毛玻璃
title author date CreateTime categories win10 uwp 毛玻璃 lindexi 2018-08-10 19:16:50 +0800 2018-2-13 17 ...
- 03.Linux-CentOS系统user用户改密码问题
问题:[user@localhost ~]$ passwdChanging password for user user.Changing password for user.(current) UN ...
- ViewMode
一.ViewMode 实现使用场景-Model枚举的情景下, 注意:枚举声明在后台的时候,需要渲染界面,页面表格使用 Bootstrap Table插件-事先通过ajax 渲染(数据库读取值1.2.3 ...
- python常用函数 F
filter(callable, list/tuple) 接收一个函数和一个序列,完成元素过滤. 例子: fnmatch(str,str) 使用底层操作系统的大小写敏感规则来匹配模式. 例子: fnm ...
- SpringBoot中jar包转war包
参考博客 https://blog.csdn.net/qq_33689414/article/details/81812761 https://blog.csdn.net/u013412772/art ...
- Sass-数字运算
在 Sass 运算中数字运算是较为常见的,数字运算包括前面介绍的:加法.减法.乘法和除法等运算.而且还可以通过括号来修改他们的运算先后顺序.和我们数学运算是一样的,一起来看个示例. .box { wi ...