Leetcode 199 Binary Tree Right Side View
2016-04-14 15:23
399 查看
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
For example:
Given the following binary tree,
You should return
BFS 每层都以从右向左的顺序扔数组里取出第一个到结果数组中,然后再对下一层同样操作。
For example:
Given the following binary tree,
1 <--- / \ 2 3 <--- \ \ 5 4 <---
You should return
[1, 3, 4].
BFS 每层都以从右向左的顺序扔数组里取出第一个到结果数组中,然后再对下一层同样操作。
class Solution(object): def rightSideView(self, root): if not root: return [] a, ans = [root], [] while a: b = [] ans.append(a[0].val) for node in a: if node.right: b.append(node.right) if node.left: b.append(node.left) a = b return ans
相关文章推荐
- boost::function使用
- Syntax error, parameterized types are only available if source level is 1.5
- 接口的调用与使用
- 理解NTFS文件系统,自制简易目录浏览器
- js 日期格式化函数
- const
- 方法:删除Provisioning Profiles(描述文件)
- LeetCode 141 Linked List Cycle
- rman--增量备份
- 关于MediaRecord一边录制一边拍照的问题
- 在JZ2440板上关于一直Boa服务器的一点心得总结
- 什么是高内聚、低耦合?
- 模板复习计划——线性与半线性数据结构维护
- 两点之间经纬度的计算
- 百度编辑器解决span被过滤, 自动加P标签
- Struts2---标签
- Android 6.0权限机制及开发流程详解
- CentOS6.5系统光纤连接存储的多路径配置及使用方法
- Number
- InvocationTargetException