4
public String smallestFromLeaf(TreeNode root) {5
build(root, new StringBuilder());9
public void build(TreeNode root, StringBuilder str) {10
if (root == null) return;12
StringBuilder sb = new StringBuilder(str).insert(0, String.valueOf(intToChar(root.val)));14
if (root.left == null && root.right == null) { // we are on a leaf node15
result = result == null || sb.toString().compareTo(result) < 0 ? sb.toString() : result;18
build(root.left, sb); // build left child19
build(root.right, sb); // build right child22
// turns an int (0-25) into a Character ex: 0 -> a, 1 -> b, 2 -> c23
public Character intToChar(int i) {24
return (char) (i + 'a');