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的更多相关文章

  1. 【LeetCode】199. Binary Tree Right Side View 解题报告(Python)

    [LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/probl ...

  2. 【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, ...

  3. 【刷题-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, ...

  4. leetcode 题解:Binary Tree Inorder Traversal (二叉树的中序遍历)

    题目: Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary ...

  5. 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 ...

  6. [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 ...

  7. 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 ...

  8. 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 ...

  9. LeetCode题解之Binary Tree Pruning

    1.题目描述 2.问题分析 使用递归 3.代码 TreeNode* pruneTree(TreeNode* root) { if (root == NULL) return NULL; prun(ro ...

随机推荐

  1. logstash收集syslog日志

    logstash收集syslog日志注意:生产用syslog收集日志!!! 编写logstash配置文件 #首先我用rubydebug测试数据 [root@elk-node1 conf.d]# cat ...

  2. select实现高并发服务器

    前言:周末学了两天网络编程,把之前的不懂一些问题基本掌握了,例如TCP状态转换图.close和shutdown函数的区别.select函数等,今天分享给大家. 一.网络编程基础知识 在写代码之前,需要 ...

  3. 五分钟轻松了解Hbase面向列的存储

    说明:从严格的列式存储的定义来看,Hbase并不属于列式存储,有人称它为面向列的存储,请各位看官注意这一点. 行式存储 传统的数据库是关系型的,且是按行来存储的.如下图: 其中只有张三把一行数据填满了 ...

  4. XML概念定义以及如何定义xml文件编写约束条件java解析xml DTD XML Schema JAXP java xml解析 dom4j 解析 xpath dom sax

    本文主要涉及:xml概念描述,xml的约束文件,dtd,xsd文件的定义使用,如何在xml中引用xsd文件,如何使用java解析xml,解析xml方式dom sax,dom4j解析xml文件 XML来 ...

  5. tcp_wrapper过滤

    1.1 wrap简介 wrap工作在内核空间和应用程序中间的库层次中.在内核接受到数据包准备传送到用户空间时都会经过库层次,对于部分(只是部分)应用程序会在经过库层次时会被wrap库文件阻挡下来检查一 ...

  6. Perl读取标准输入<STDIN>、读取文件输入<>和chomp函数

    读取标准输入<STDIN> <STDIN>表示从标准输入中读取内容,如果没有,则等待输入.<STDIN>读取到的结果中,如果没有意外,都会自带换行符. 例如,tes ...

  7. QT 应用程序测试

    添加环境 export QTEDIR='/Qt5' export QTINC='/Qt5/include/' export QTLIB='/Qt5/lib' export QT_QPA_FB_TSLI ...

  8. 连接MySQL的10060错误:Can't connect to MySQL server on '*.*.*.*'(10060)

    使用MySQL的图形界面管理工具Navicat for MySQL连接Mysql数据库时提示错误:Can't connect to MySQL server (10060) [出现该问题可能的原因:] ...

  9. js如何获取url参数

    匹配URL参数的正则是: var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", ...

  10. nginx支持跨域访问

    1,进入nginx的html目录 vim ./crossdomain.xml 具体路径: /usr/local/nginx/html/crossdomain.xml 2,在crossdomain.xm ...