257. Binary Tree Paths
来源:互联网 发布:seo软件下载 编辑:程序博客网 时间:2024/06/06 11:43
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
1 / \2 3 \ 5
All root-to-leaf paths are:
["1->2->5", "1->3"]
public List<String> binaryTreePaths(TreeNode root) { List<String> res = new ArrayList<String>(); if(root!=null) helper(root, Integer.toString(root.val), res); return res; } public void helper(TreeNode root, String path, List res){ if(root.left==null&&root.right==null){ res.add(path); } if(root.left!=null){ helper(root.left, path + "->" + root.left.val, res); } if(root.right!=null){ helper(root.right, path + "->" + root.right.val, res); } }
0 0
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 257. Binary Tree Paths
- 360面试题——猜数
- Java同步工具类——栅栏[CyclicBarrier]
- 实验三 无损数据压缩编解码实验(Huffman编解码)
- Tomcat启动时报java.io.EOFException
- 等价二叉树
- 257. Binary Tree Paths
- ScrollView和listView嵌套使用
- TOMCAT JAVA_HOME or JRE_HOME environment variable is not defined correctly
- 理解RESTful架构
- C++ 二叉树创建、遍历访问、删除
- Leetcode 437. Path Sum III
- caffe训练提示top blob 'data' produced multiple sour解决办法
- FZU1062 NBUT1225
- Tomcat 优化方案 和 配置详解