/**
* 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:
void getPath(TreeNode* root,vector<string> &result,vector<int> &path){
path.push_back(root->val);
if(root->left==NULL&&root->right==NULL){
string sPath;
for(int i=0;i<path.size()-1;i++){
sPath+=to_string(path[i]);
sPath+="->";
}
sPath+=to_string(path[path.size()-1]);
result.push_back(sPath);
return;
}
if(root->left){
getPath(root->left,result,path);
path.pop_back();
}
if(root->right){
getPath(root->right,result,path);
path.pop_back();
}
}
vector<string> binaryTreePaths(TreeNode* root) {
vector<string> result;
vector<int> path;
if(root==NULL) return result;
getPath(root,result,path);
return result;
}
};