/**
* 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> binaryTreePaths(TreeNode* root) {
vector<string> res = {};
if (root){
if (root->left == NULL && root->right == NULL){
res.push_back(to_string(root->val));
return res;
}
else{
vector<string> temp = binaryTreePaths(root->left);
for (auto path:temp) res.push_back(to_string(root->val) + "->" + path);
temp = binaryTreePaths(root->right);
for (auto path:temp) res.push_back(to_string(root->val) + "->" + path);
}
}
return res;
}
};