Skip to content

Commit c9b98c6

Browse files
authored
Update 285-inorder-successor-in-bst.js
1 parent 37c6cff commit c9b98c6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

285-inorder-successor-in-bst.js

+15
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ const inorderSuccessor = function(root, p) {
4646
const left = root == null ? null : inorderSuccessor(root.left, p)
4747
return left != null && left.val > p.val ? left : root
4848
}
49+
50+
// another
51+
52+
const inorderSuccessor = function(root, p) {
53+
let succ = null
54+
while(root) {
55+
if (p.val < root.val) {
56+
succ = root
57+
root = root.left
58+
} else {
59+
root = root.right
60+
}
61+
}
62+
return succ
63+
}

0 commit comments

Comments
 (0)