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; * ...
随机推荐
- Zepto v1.0-1源码注解
/* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ ;(funct ...
- 如何创建 Qt 插件?
如何创建 Qt 插件? 简单三部曲 定义接口类或接口基类并使用 Q_DECLARE_INTERFACE 宏进行声明 所有的插件都需要继承该基类并继承 QObject(不带界面插件) or QWidge ...
- 75.Binary Tree Maximum Path Sum(二叉树的最大路径和)
Level: Hard 题目描述: Given a non-empty binary tree, find the maximum path sum. For this problem, a pa ...
- bzoj3097 Hash Killer I
Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special Judge Description 这天天气不错,hzhwcmhf神犇给 ...
- elasticsearch 深入 —— Search After实时滚动查询
Search After 一般的分页需求我们可以使用form和size的方式实现,但是这种分页方式在深度分页的场景下应该是要避免使用的.深度分页会随着请求的页次增加,所消耗的内存和时间的增长也是成比例 ...
- 2018-2-13-win10-UWP-RSS阅读器
title author date CreateTime categories win10 UWP RSS阅读器 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 1 ...
- linux驱动启动顺序
首先,我们可以查看Linux内核编译完成后的System.map文件,在这个文件中我们可以看到macb(dm9161驱动模块)链接到了dm9000驱动之前,如下所示: c03b6d40 t __ini ...
- Linux学习笔记之VIM编辑器
此处根据需要,只罗列一些常用的指令和用法 五.VIM程序编辑器 Vi与vim Vi打开文件没有高亮注释,vim有,且vim是vi的高级版本 Vim默认打开文件为命令模式 i ...
- 再读js正则表达式
正则表达式定义 在js中有两种方式来定义正则表达式, 第一种是类似perl的语法来定义一个正则表达式,我们把它叫做正则表达式字面量法: var expression = /pattern/flag 其 ...
- WPF 几种常用控件样式的总结
这里把wpf中几种常用样式总结一下,后期可以直接拷贝使用,呵呵 一.Button <ResourceDictionary xmlns="http://schemas.microsoft ...