Skip to content

Commit 4977b73

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

285-inorder-successor-in-bst.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,18 @@ function dfs(node, arr, res, target) {
2323
arr.push(node)
2424
dfs(node.right, arr, res, target)
2525
}
26+
27+
// another
28+
29+
const inorderSuccessor = function(root, p) {
30+
let last = null
31+
const chk = node => {
32+
if(!node) return
33+
const l = chk(node.left)
34+
if(l !== undefined) return l
35+
if(last === p) return node
36+
last = node
37+
return chk(node.right)
38+
}
39+
return chk(root)
40+
};

0 commit comments

Comments
 (0)