Binary Tree Right Side View
2015-08-20 21:11
204 查看
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
For example:
Given the following binary tree,
1 <--- / \ 2 3 <--- \ \ 5 4 <---
You should return
[1, 3, 4].
public class Solution { public List<Integer> rightSideView(TreeNode root) { List<Integer> result = new ArrayList<Integer>(); helper(root,result,0); return result; } public void helper(TreeNode node, List<Integer> result, int count){ if(node == null){ return; } if(count == result.size()){ result.add(node.val); } helper(node.right,result,count + 1); helper(node.left,result,count + 1); } }
相关文章推荐
- 个人--2015 关于管理的书
- 类和接口的设计原则
- 02-线性结构4. Pop Sequence (25)
- 多线程 - 01.多线程概述
- 个人--看见,是真正的慈悲
- win8下 node.js模块msnodesql的配置(附连接sqlserver2008 demo)
- jQuery实现页面滚动时顶部动态显示隐藏
- UNIX环境高级编程(3):UNIX标准化及实现(1)
- iOS8使用CoreLocation获取当前地理位置
- Number Sequence(http://acm.hdu.edu.cn/showproblem.php?pid=1005)
- 2015-08-20
- android 添加视频、图片、录音上传(三)
- Java心得18
- R语言_基本统计分析
- 知识扩展----为什么计算机时间要从1970年1月1日开始算起?
- POJ 题目3237 Tree(Link Cut Tree边权变相反数,求两点最大值)
- Flex中HTTPService与java后台通信
- HDU 3336 KMP
- MVC模式和代理模式
- poj3259Wormholes【最短路SPFA判断负环】