#988
Smallest String Starting From Leaf
specialist · 705 · lc medium +30 · verified · 61.1% accepted · 2,410 likes · top 61%
Description
In binary tree root, each node's value is in [0, 25] representing 'a' through 'z'. For every root-to-leaf path, read it backwards (leaf first) to form a string. Return the lexicographically smallest of all such leaf-to-root strings.
Example 1:
Input: root = [0,1,2,3,4,3,4]
Output: "dba"
Example 2:
Input: root = [25,1,3,1,3,0,2]
Output: "adz"
Example 3:
Input: root = [2,2,1,null,1,0,null,0]
Output: "abc"
Code
1
2
3
4
5
6
7
8
9