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

class Solution {
public:
    void recursively(TreeNode* root, vector<string>& paths, string path) {
        // If the node is a leaf, add the current path to the paths vector
        if (root->left == nullptr && root->right == nullptr) {
            path += to_string(root->val);  // Add the leaf node value to the path
            paths.push_back(path);         // Add the complete path to paths
            return;
        }
        
        // Add the current node value to the path
        path += to_string(root->val) + "->";
        
        // Recursively call for left and right children if they exist
        if (root->left != nullptr) {
            recursively(root->left, paths, path);
        }
        if (root->right != nullptr) {
            recursively(root->right, paths, path);
        }
    }
    
    vector<string> binaryTreePaths(TreeNode* root) {
        vector<string> result;
        if (root == nullptr) return result;  // Return empty vector if root is null
        recursively(root, result, "");
        return result;
    }
};

16700