https://leetcode.com/problems/binary-tree-paths/description/
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<string> vec;
void Path(TreeNode* root, string t)
{
if(!root->left && !root->right){
vec.push_back(t);
return;
}
if(root->left) Path(root->left, t+"->"+to_string(root->left->val));
if(root->right) Path(root->right, t+"->"+to_string(root->right->val));
}
vector<string> binaryTreePaths(TreeNode* root) {
if(!root) return vec;
Path(root, to_string(root->val));
return vec;
}
};