Skip to content

Commit 89a4519

Browse files
authored
Update 988-smallest-string-starting-from-leaf.js
1 parent cb1d06e commit 89a4519

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

988-smallest-string-starting-from-leaf.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ function arrToStr(arr) {
3939
}
4040
return res
4141
}
42+
43+
// another
44+
45+
const smallestFromLeaf = function(root) {
46+
if (!root) return ''
47+
const char = String.fromCharCode(97 + root.val)
48+
let left = smallestFromLeaf(root.left)
49+
let right = smallestFromLeaf(root.right)
50+
if (!left) return right + char
51+
if (!right) return left + char
52+
return (left < right ? left : right) + char
53+
};

0 commit comments

Comments
 (0)