> For the complete documentation index, see [llms.txt](https://ugopireddy.gitbook.io/leet-code-solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ugopireddy.gitbook.io/leet-code-solutions/solutions-251---300/257-binary-tree-paths---easy.md).

# 257 Binary Tree Paths - Easy

### Problem

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"]

### Solutions:

```java
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public List<String> binaryTreePaths(TreeNode root) {
        List<String> result = new LinkedList<String>();
        process(root, "", result);
        return result;
    }
    private void process(TreeNode node, String curr, List<String> result) {
        if (node == null) {
            return;
        }
        String next = curr + "->" + node.val;
        if (node.left == null && node.right == null) {
            result.add(next.substring(2));
        }
        process(node.left, next, result);
        process(node.right, next, result);
    }
}
```
