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 ...
随机推荐
- Linux编程 17 文件权限(权限设置chmod,改变文件属主属组关系chown,chgrp)
一. 概述 如果创建了一个目录或文件,有时会需要改变它的安全性设置,在linux系统上有一些工具可以完成这任务,包括使用chmod命令改变已有默认权限,分别能对属主,属组,其它用户的权限的控制分别以读 ...
- .Net Core 2.0 preview1实现自定义认证方案
Microsoft.Authentication的使用方法在2.0中发生了比较大的变化,在1.1中认证配置是在Configure中完成. public void ConfigureServices(I ...
- 并发服务器三种实现方式之进程、线程和select
前言:刚开始学网络编程,都会先写一个客户端和服务端,不知道你们有没有试一下:再打开一下客户端,是连不上服务端的.还有一个问题不知道你们发现没:有时启服务器,会提示“Address already in ...
- 如何用vue-router为每个路由配置各自的title
传统方法 以前在单页面路由中,就只能在html文件中定一个固定的网站的title.如果想要动态的去修改,需要使用如下的方法. document.title = '这是一个标题'; 这样会让我们做很多无 ...
- NewLife.Redis基础教程
X组件缓存架构以ICache接口为核心,包括MemoryCache.Redis和DbCache实现,支持FX和netstandard2.0!后续例程与使用说明均以Redis为例,各缓存实现类似. Re ...
- linux 命令 — tr
tr 对stdin字符进行替换.删除和压缩,基本形式 tr [options] set1 set2 将输入的字符串中的set1字符转换为set2中对应位置的字符 set1.set2表示字符集,如果se ...
- centos7安装遇到的坑
1.安装中遇到what is the location of the gcc program on your machine 直接输入 no.意思就是跳过gcc的安装了.但是系统虽然安装了vmware ...
- man mountd(rpc.mountd中文手册)
本人译作集合:http://www.cnblogs.com/f-ck-need-u/p/7048359.html rpc.mountd() System Manager's Manual rpc.mo ...
- 学会这个删库再也不用跑路了~ --技术流ken
前言 相信每一个学IT的人或多或少都听说过从删库到跑路这个梗~下图也是在各种交流群屡禁不止,新人听着也是瑟瑟发抖. 人们茶余饭后,街头巷角难免要问... 下面技术流ken就教给各位新手们一招删库再也不 ...
- springBoot系列-->springBoot注解大全
一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...