class Solution {
public:
vector<string> binaryTreePaths(TreeNode* root) {
if (!root) return {};
vector<string> ret;
string cur = to_string(root->val);
dfs(root, cur, ret);
return ret;
}
void dfs(TreeNode* root, string cur, vector<string>& ret) {
if (!root->left && !root->right) {
ret.push_back(cur);
return;
}
if (root->left) dfs(root->left, cur + "->" + to_string(root->left->val), ret);
if (root->right) dfs(root->right, cur + "->" + to_string(root->right->val), ret);
}
};