Leetcode-199. Binary Tree Right Side View
来源:互联网 发布:华为软件工程师 知乎 编辑:程序博客网 时间:2024/06/08 03:07
前言:为了后续的实习面试,开始疯狂刷题,非常欢迎志同道合的朋友一起交流。因为时间比较紧张,目前的规划是先过一遍,写出能想到的最优算法,第二遍再考虑最优或者较优的方法。如有错误欢迎指正。博主首发CSDN,mcf171专栏。
博客链接:mcf171的博客
——————————————————————————————
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]
.
public class Solution { private int see_high = 0; public List<Integer> rightSideView(TreeNode root) { List<Integer> results = new ArrayList<Integer>();search(root,results,0);return results; } public void search(TreeNode root,List<Integer> results, int depth){if(root == null) return;if(depth >= see_high){ results.add(root.val); see_high++; }search(root.right,results,depth+1);search(root.left,results,depth +1); }}
0 0
- [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
- [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
- 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
- spring与redis集成之aop整合方案
- 内存中生成的Bitmap的背景颜色怎么控制
- CreateWindow
- Java语言基础-9.方法三要素
- Spark2.1新特性
- Leetcode-199. Binary Tree Right Side View
- Eclipse安装Activiti Designer插件
- spring-boot使用注解获取配置文件中的值
- Lua中的模式
- 蓝鸥iOS从零基础到精通就业-OC语言入门 字典
- golang中fmt的'占位符'使用
- 前面的总结不太好,找了一篇总结的挺好的,仅供学习参考
- 求软键盘出现界面上推的距离可以自己控制的方法
- suricata 3.1 源码分析34 (FlowWorker处理流程3 - 流重用)