原题链接
class Solution {
public:
vector ans;
vector binaryTreePaths(TreeNode* root) {
dfs(root, "");
return ans;
}
void dfs(TreeNode* root, string path){
if(!root) return;
path += to_string(root -> val) + "->";
if(!root -> left && !root -> right){
path.pop_back();
path.pop_back();
ans.push_back(path);
return;
}
dfs(root -> left, path);
dfs(root -> right, path);
}
};



