257. Binary Tree Paths 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920212223class Solution {public: vector<string> ret; void traverse(TreeNode *root, string path){ if(!root) return; if(!root->right && !root->left){ path+=to_string(root->val); ret.push_back(path); return; } else path+=to_string(root->val)+"->"; traverse(root->left,path); traverse(root->right,path); } vector<string> binaryTreePaths(TreeNode* root) { string path; traverse(root, path); return ret; }};