2
* Definition for a binary tree node.7
* TreeNode() : val(0), left(nullptr), right(nullptr) {}8
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}9
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),16
void solve(TreeNode *root, string cur) {18
cur.push_back((char)('a' + root->val)); // converting integer to corresponding characer19
if (!root->left and !root->right) {20
// reversing the string since it is computed from root to leaf, but we22
reverse(cur.begin(), cur.end());23
if (res == "" or cur < res) res = cur; // updating the result based on lexicographical order26
solve(root->left, cur);27
solve(root->right, cur);30
string smallestFromLeaf(TreeNode *root) {