# 257. Binary Tree Paths

{% embed url="<https://leetcode.com/problems/binary-tree-paths/>" %}

* 确认根节点到每个叶子节点的路径，显然dfs
* 递归过程中需要传递当前已经记录的路径
* 到叶子节点就把完整路径加进结果

```python
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def binaryTreePaths(self, root: TreeNode) -> List[str]:
        if not root: return []
        paths = []
        def dfs(node, path, res):
            if not node.left and not node.right:
                res.append(path+str(node.val))
            if node.left:
                dfs(node.left, path+str(node.val)+"->", res)
            if node.right:
                dfs(node.right, path+str(node.val)+"->", res)
        dfs(root, "", paths)
        return paths
```
