199. Binary Tree Right Side View
来源:互联网 发布:java什么是方法的定义 编辑:程序博客网 时间:2024/06/14 01:13
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,
1 <--- / \2 3 <--- \ \ 5 4 <---
You should return [1, 3, 4]
.
从右边看一棵树,吧能看到的节点记录下来。也就是说每一层只能看到一个节点,最后list的大小等于层数;
利用这个特点来判断遍历到的值是否需要加到list中去,
public class Solution { List<Integer> list=new ArrayList<Integer>(); public List<Integer> rightSideView(TreeNode root) { if(root!=null) right(root,0); return list; } public void right(TreeNode root,int level){ if(root==null) return ; if(level==list.size()) list.add(root.val); right(root.right,level+1); right(root.left,level+1); }}
0 0
- Tree-----199. Binary Tree Right Side View
- [LeetCode]199.Binary Tree Right Side View
- LeetCode 199. Binary Tree Right Side View
- [leetcode] 199.Binary Tree Right Side View
- [leetcode] 199. Binary Tree Right Side View
- [LeetCode]199. Binary Tree Right Side View
- 199. Binary Tree Right Side View LeetCode
- leetcode 199. Binary Tree Right Side View
- [LeetCode]199. Binary Tree Right Side View
- [LeetCode]199. Binary Tree Right Side View
- 199. Binary Tree Right Side View
- [LeetCode] 199. Binary Tree Right Side View
- LeetCode *** 199. Binary Tree Right Side View
- LeetCode 199. Binary Tree Right Side View
- 199. Binary Tree Right Side View
- 199. Binary Tree Right Side View
- 199. Binary Tree Right Side View
- 199. Binary Tree Right Side View
- python3爬取torrent种子链接
- 2016秋季练习
- csdn如何转载别人的文章
- hibernate框架学习(1)
- Some Questions of Process API(1)
- 199. Binary Tree Right Side View
- Android之TabLayout的简单使用
- WPF 触发器例子
- 微信小程序(应用号)调试工具内测破解方法
- [LeetCode]3. Longest Substring Without Repeating Characters 寻找最长子串&set的用法
- 公众平台小程序文档和工具
- javascript高级程序设计第七章(函数表达式、闭包)笔记
- Python参数小结
- 查看jks文件信息