# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def rightSideView(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
def right(level):
if len(level) == 0:
return []
return [level[-1].val]+right([x for i in level for x in [i.left,i.right] if x])
if not root:
return []
return right([root])

@https://github.com/Linzertorte/LeetCode-in-Python/blob/master/BinaryTreeRightSideView.py#L2

leetcode Binary Tree Right Side View python的更多相关文章

  1. [LeetCode] Binary Tree Right Side View 二叉树的右侧视图

    Given a binary tree, imagine yourself standing on the right side of it, return the values of the nod ...

  2. [leetcode]Binary Tree Maximum Path Sum @ Python

    原题地址:https://oj.leetcode.com/problems/binary-tree-maximum-path-sum/ 题意: Given a binary tree, find th ...

  3. [leetcode]Binary Tree Right Side View

    好久不写了,最近忙毕业论文呢. 这个题,就是说一个二叉树,你从右边看,你能看到的数有哪些(会被遮挡) 其实抽象出来就是说...二叉树每层最右边的数有哪些.. 那我们按层遍历一次就好了. /** * D ...

  4. LeetCode Binary Tree Right Side View (DFS/BFS)

    题意: 给一棵二叉树,要求收集每层的最后一个节点的值.按从顶到底装进vector返回. 思路: BFS比较简单,先遍历右孩子就行了. /** * Definition for a binary tre ...

  5. leetcode Binary Tree Level Order Traversal python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

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

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

  7. leetcode 199 :Binary Tree Right Side View

    // 我的代码 package Leetcode; /** * 199. Binary Tree Right Side View * address: https://leetcode.com/pro ...

  8. leetcode 199. Binary Tree Right Side View 、leetcode 116. Populating Next Right Pointers in Each Node 、117. Populating Next Right Pointers in Each Node II

    leetcode 199. Binary Tree Right Side View 这个题实际上就是把每一行最右侧的树打印出来,所以实际上还是一个层次遍历. 依旧利用之前层次遍历的代码,每次大的循环存 ...

  9. Leetcode之深度优先搜索(DFS)专题-199. 二叉树的右视图(Binary Tree Right Side View)

    Leetcode之深度优先搜索(DFS)专题-199. 二叉树的右视图(Binary Tree Right Side View) 深度优先搜索的解题详细介绍,点击 给定一棵二叉树,想象自己站在它的右侧 ...

随机推荐

  1. js正则判断电话/手机/邮箱/

    用途:校验ip地址的格式 输入:strIP:ip地址返回:如果通过验证返回true,否则返回false:*/ function isIP(strIP) { if (isNull(strIP)) ret ...

  2. 各版本SDK Tools及ADT下载技巧

    我们在开发的时候,尤其是使用Eclipse安装ADT插件进行环境配置,我们需要从下载ADT插件及SDK,当我们从官网下载的时候,有的时候可能找不到下载的地方或者下载不到自己想要的版本,我就在此总结下如 ...

  3. ubuntu 配置JDK环境变量

    ubuntu 配置JDK环境变量 (2011-11-25 16:45:59) 转载▼ 标签: ubuntu jdk 环境变量 杂谈 分类: Linux_Ubuntu_CentOs 过程如下: 1. 先 ...

  4. EF6 Codefirst+MySql 数据库迁移

    简介 项目使用MSSql作为数据库,但是因为SQL服务器贵那么一点,并发连接差那么一点,要把数据迁移到MySQL,顺带迁移过程以及问题. 环境 Visual Studio 2013 MySQL 5.7 ...

  5. [Linked List]Intersection of Two Linked Lists

    Total Accepted: 53721 Total Submissions: 180705 Difficulty: Easy Write a program to find the node at ...

  6. PLSQL Developer建表时注释(COMMENT)中文乱码的解决方案(Windows)

    简单的让你无法想象! 处理方法:在环境变量中新增系统变量 以下变量值对: 变量名:NLS_LANG变量值:AMERICAN_AMERICA.ZHS16GBK 好了

  7. 解决Button在IE6、7下的自适应宽度问题

    很早就遇到过这么个小问题,但由于其并未影响到实际作用和美观就没有正面解决它,现在,我们来试着解决它. 写一个Button,有两种方式:其一,直接button标签:其二,input type=”butt ...

  8. Android 监听网络变化

    Android 监听网络变化

  9. Looper、Hander、HandlerThread

    一.Message .Looper.Handler之间的关系 1.系统发送的Message消息传送给Handler,Handler将Message放入自己的looper队列的底部   然后再从Loop ...

  10. C语言 —— 括号配对问题(不使用栈)

    最近在南阳理工的OJ上刷题,看到一个有点意思的题目 网上的答案大多都使用了栈,可惜我还没有学习数据结构,所以只能用简单的方法来解决 题目的链接在这 http://acm.nyist.net/Judge ...