<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.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<string> binaryTreePaths(TreeNode* root) {
        vector<vector<int>> s1;
        vector<int> t;
        string p="";
        vector<string> f;
        pathSum(root,s1,t);
        for(auto s:s1){
            for(int i=0;i<s.size();i++){
                p+=to_string(s[i]);
                if(i!=s.size()-1){
                    p+="->";
                }
            }
            f.push_back(p);
            p="";
        }
        return f;

    }
    void pathSum(TreeNode *root,vector<vector<int>> &s ,vector<int> &v){
        if(root && root->left==nullptr && root->right==nullptr){
            v.push_back(root->val);
            s.push_back(v);
            v.pop_back();
        }
        else{
           if(root){
                v.push_back(root->val);
                pathSum(root->left,s,v);
                v.pop_back();
                v.push_back(root->val);
                pathSum(root->right,s,v);
                v.pop_back();
           }
        }
    }
};
16200