LeetCode题解之Binary Tree Right Side View
1、题目描述
2、问题分析
使用层序遍历
3、代码
vector<int> v;
vector<int> rightSideView(TreeNode* root) {
if (root == NULL)
return v; queue<TreeNode*> q;
q.push(root); while (!q.empty()) {
int size = q.size();
for(int i = ; i < size; i++) {
TreeNode *node = q.front();
if (node->left != NULL)
q.push(node->left);
if (node->right != NULL)
q.push(node->right); if (i == size - )
v.push_back(node->val);
q.pop();
}
} return v; }
LeetCode题解之Binary Tree Right Side View的更多相关文章
- 【LeetCode】199. Binary Tree Right Side View 解题报告(Python)
[LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/probl ...
- 【LeetCode】199. Binary Tree Right Side View
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, ...
- 【刷题-LeetCode】199 Binary Tree Right Side View
Binary Tree Right Side View Given a binary tree, imagine yourself standing on the right side of it, ...
- leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)
题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...
- LeetCode OJ 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- [LeetCode 题解]: Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...
- LeetCode OJ:Binary Tree Right Side View(右侧视角下的二叉树)
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...
- leetcode题解:Construct Binary Tree from Preorder and Inorder Traversal (根据前序和中序遍历构造二叉树)
题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume t ...
- LeetCode题解之Binary Tree Pruning
1.题目描述 2.问题分析 使用递归 3.代码 TreeNode* pruneTree(TreeNode* root) { if (root == NULL) return NULL; prun(ro ...
随机推荐
- IntelliJ IDEA 代码字体大小的快捷键设置放大缩小(很实用)(图文详解)
不多说,直接上干货! 这是在设置IntelliJ IDEA 代码字体的快捷键设置缩小: 怎么达到的了,就是ctrl + 你的鼠标滑扭往下 这是在设置IntelliJ IDEA 代码字体的快捷键设置 ...
- 您的快递(高并发服务器之poll和epoll)请签收
前言 之前已经介绍过select函数,请参考这篇博客:https://www.cnblogs.com/liudw-0215/p/9661583.html,原理都是类似的,有时间先阅读下那篇博客,以便于 ...
- 在Mac下连接阿里云服务器
1.登录 ssh root@IP地址 eg:00.00.00.00 2.新建用户 useradd -d /home/用户名 -m 根目录名 (这条命令,就是创建一个新用户,并给该用户在home目录下创 ...
- Linux软件包管理之RPM命令
目录 1.Linux软件包分类 一.源码包 二.二进制包 2.rpm 包命名规则 3.rpm包安装 4.rpm包升级 5.rpm包卸载 6.查询rpm包是否安装 7.查询软件包的详细信息 8.查询软件 ...
- Thrift架构介绍
Thrift是一个跨语言的服务部署框架,最初由Facebook于2007年开发,2008年进入Apache开源项目.Thrift通过一个中间语言(IDL, 接口定义语言)来定义RPC的接口和数据类型, ...
- 5-15 bootcss 之 modal 以及 jquery ui 之datepicker 小记
最近公司在用bootstrap和Jquery UI做项目,类似与OA的东西前两天碰到点问题,记录一下.希望读者不要在遇到和我一样的问题. 1 datepicker.不知道怎么自己下载的bootcss里 ...
- ES6 使用数据类型Set求交集、并集、差集
前言 ES6新增了数据类型Set,它是一种类似数组的数据结构.但它和数组的不同之处在于它的成员都是唯一的,也就是说可以用来去除数组重复成员. Set本身是一个构造函数用来生成Set数据结构. cons ...
- Python爬虫之自制英汉字典
最近在微信公众号中看到有人用Python做了一个爬虫,可以将输入的英语单词翻译成中文,或者把中文词语翻译成英语单词.笔者看到了,觉得还蛮有意思的,因此,决定自己也写一个玩玩~~ 首先我们的爬虫 ...
- Docker在Linux上运行NetCore系列(一)配置运行DotNetCore控制台
转发请注明此文章作者与路径,请尊重原著,违者必究. 系列文章:https://www.cnblogs.com/alunchen/p/10121379.html 本篇文章操作系统信息 Linux:ubu ...
- Redis常用命令与配置
常用命令 测试客户端与服务器是否正常连接:ping ( 补:返回pong表示成功 ) 正则获取键:keys pattern 判断一个键是否存在:exists key 删除一个键:del key 获 ...