Lexicographically Smallest Root-to-Leaf String
Problem statement
Each binary-tree node contains an integer from 0 through 25 representing letters a through z. Return the lexicographically smallest string encountered along a path from the root to any leaf.
Return the empty string for an empty tree.
Function
smallestRootToLeaf(root: TreeNode) → StringExamples
Example 1
root = [0,1,2,3,4,3,4]return = "abd"The root-to-leaf strings are abd, abe, acd, and ace; abd is smallest.
Constraints
- The tree contains at most
10^5nodes. - Every node value is between 0 and 25.