leetcode-java-257. Binary Tree Paths
来源:互联网 发布:gre软件 编辑:程序博客网 时间:2024/06/05 03:15
/*思路:1.采用递归左子树递归找到路径(根节点+左子树)右子树递归找到路径(根节点+右子树)2.递归停止条件:递归到叶子节点时终止,即root.left==null && root.right == null时,将字符串add到result中。 */ public class Solution { public List<String> binaryTreePaths(TreeNode root) { List<String> result = new LinkedList<String>(); if(root == null) { return result; } findPaths(result,"",root); return result; } public void findPaths(List<String> result,String temp,TreeNode root) { if(root == null) { return; } if(root.left == null && root.right == null) { result.add(temp+Integer.toString(root.val)); return; } findPaths(result,temp+Integer.toString(root.val)+"->",root.left); findPaths(result,temp+Integer.toString(root.val)+"->",root.right); } }
0 0
- Leetcode:257. Binary Tree Paths(JAVA)
- leetcode-java-257. Binary Tree Paths
- LeetCode-257. Binary Tree Paths (Java)
- [leetcode] 257. Binary Tree Paths
- 257. Binary Tree Paths LeetCode
- 【LeetCode】257. Binary Tree Paths
- LeetCode 257. Binary Tree Paths
- LeetCode *** 257. Binary Tree Paths
- leetcode 257. Binary Tree Paths
- LeetCode 257. Binary Tree Paths
- Leetcode 257. Binary Tree Paths
- LeetCode-257.Binary Tree Paths
- 【leetcode】257. Binary Tree Paths
- [Leetcode]257. Binary Tree Paths
- LeetCode - 257. Binary Tree Paths
- LeetCode 257. Binary Tree Paths
- [leetcode] 257. Binary Tree Paths
- LeetCode 257. Binary Tree Paths
- html 三列布局(两列固定宽度,一列自适应)
- 程序员必学的linux命令(1)
- python实现FSC
- C语言-堆栈、队列 区别
- TCP知识4
- leetcode-java-257. Binary Tree Paths
- 数据结构实验之排序七:选课名单
- gcc 学习笔记(备忘)
- HDU Problem 1179 Ollivanders: Makers of Fine Wands since 382 BC.【二分图匹配】
- 数组排序 —— 快排算法思想应用(三色排序)
- Android之Handler机制
- Map的取值方式介绍
- 重载运算符
- 解决eclipse/myeclipse导入项目时出现红色叹号的方法