<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p>

<p>A <strong>leaf</strong> is a node with no children.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-tree.jpg" style="width: 207px; height: 293px;" />
<pre>
<strong>Input:</strong> root = [1,2,3,null,5]
<strong>Output:</strong> [&quot;1-&gt;2-&gt;5&quot;,&quot;1-&gt;3&quot;]
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> root = [1]
<strong>Output:</strong> [&quot;1&quot;]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li>The number of nodes in the tree is in the range <code>[1, 100]</code>.</li>
	<li><code>-100 &lt;= Node.val &lt;= 100</code></li>
</ul>

# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val  # Current node's value
        self.left = left  # Left child
        self.right = right  # Right child
class Solution:
    def binaryTreePaths(self, root):
        # Helper function to perform recursion
        def construct_paths(node, path):
            if node:
                # Recursive Step: Add the current node's value to the path
                path += str(node.val)
                
                # Base Case: If the node is a leaf (no children), we have a complete path
                if not node.left and not node.right:
                    # Combine: Add the completed path to the result list
                    paths.append(path)
                else:
                    # Recursive Step: Continue the path by adding '->' 
                    path += "->"
                    
                    # Recursive Step: Recursively call for the left child
                    construct_paths(node.left, path)
                    
                    # Recursive Step: Recursively call for the right child
                    construct_paths(node.right, path)
        
        paths = []  # This list will store all the paths from root to leaf
        construct_paths(root, "")  # Start recursion with the root node and an empty path
        return paths  # Return the list of all root-to-leaf paths


16400