# Easy-题目53：257. Binary Tree Paths

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 class Solution {
List<String> res = new ArrayList<String>();
public List<String> binaryTreePaths(TreeNode root) {
if(root != null) findPaths(root,String.valueOf(root.val));
return res;
}
private void findPaths(TreeNode n, String path){
if(n.left == null && n.right == null) res.add(path);
if(n.left != null) findPaths(n.left, path+"->"+n.left.val);
if(n.right != null) findPaths(n.right, path+"->"+n.right.val);
}
}

3ms,beats 27.22%,众数3ms,47.28%.

#### 【LeetCode】257. Binary Tree Paths 解题报告

2016-05-22 10:57:58

#### 257. Binary Tree Paths [easy] (Python)

2016-06-18 15:55:42

#### LeetCode257——Binary Tree Paths

2015-08-17 21:51:08

#### leetcode-java-257. Binary Tree Paths

2016-08-17 20:55:44

#### leetcode 257: Binary Tree Paths

2015-08-19 20:14:04

#### [LeetCode] Binary Tree Paths - 二叉树基础系列题目

2015-09-09 00:58:21

#### 257. Binary Tree Paths | 二叉树的路径

2017-04-14 20:04:49

#### LeetCode *** 113. Path Sum II

2016-04-19 14:41:15

#### 257. Binary Tree Paths

2018-07-03 15:31:42

#### 257. Binary Tree Paths*

2016-12-21 19:55:23