Skip to content

Commit 37c6cff

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

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

285-inorder-successor-in-bst.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ const inorderSuccessor = function(root, p) {
3838
}
3939
return chk(root)
4040
};
41+
42+
// another
43+
44+
const inorderSuccessor = function(root, p) {
45+
while (root != null && root.val <= p.val) root = root.right
46+
const left = root == null ? null : inorderSuccessor(root.left, p)
47+
return left != null && left.val > p.val ? left : root
48+
}

0 commit comments

Comments
 (0)