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; * ...
随机推荐
- ThreadLocal和单例对象比较
单例对象: 自始至终只有一个对象 当线程并发,每个线程需要自己独立的资源变量处理不同的业务时,单例对象远远不能满足需求 因此可以采用ThreadLocal模式 : 每个线程有自己独立的资源变量 ...
- CentOS安装ruby, Haskall,io语言
安装ruby yum install ruby irb rdoc 安装Haskall yum install ghc 安装io语言 安装io语言,需要先安装cmake不过不要使用yum来进行安装,yu ...
- 什么是HTTP协议?常用的状态码有哪些?
一.HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的 ...
- 70.Trapping Rain Water(容水量)
Level: Hard 题目描述: Given n non-negative integers representing an elevation map where the width of e ...
- .ef core 多对对关系的关联方法
最近在用.net core 重构博客,在使用ef core连表查询时,遇到了一些问题.记录一下. 关系:一个博客可以有多个标签,一个标签可以属于多个博客,博客和标签之间存在多对多的关系 下面是实体代码 ...
- python车牌精确定位
#coding=utf-8 import cv2 # 使用的是HyperLPR已经训练好了的分类器 watch_cascade = cv2.CascadeClassifier('model/casca ...
- 2018-8-10-如何使用-Q#
title author date CreateTime categories 如何使用 Q# lindexi 2018-08-10 19:16:51 +0800 2018-2-13 17:23:3 ...
- ActiveMQ修改端口号
1.修改tcp端口号 安装目录下的conf/activemq.xml 2.修改管理页面的访问端口号 安装目录下的conf/jetty.xml
- Nexus搭建Maven私服中央仓库
一.概述 1.概要 现在的项目基本都是用Maven来管理工程,这样一来在公司内容搭建一个私服就非常有必要了,这样一来可以管理公司内部用的JAR包,也可以管理第三方的各种JAR来,以免每次都要从外网的仓 ...
- CentOS 7.4 安装python3及虚拟环境
[转]:https://www.centos.bz/2018/05/centos-7-4-%e5%ae%89%e8%a3%85python3%e5%8f%8a%e8%99%9a%e6%8b%9f%e7 ...