We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0c43847 commit cdac5f7Copy full SHA for cdac5f7
src/main/kotlin/leetcode/inorder-successor-in-bst-ii/Solution.kt
@@ -0,0 +1,25 @@
1
+package leetcode.`inorder-successor-in-bst-ii`
2
+
3
+import TreeNode
4
5
+class Solution {
6
+ fun inorderSuccessor(node: Node?): Node? {
7
+ node ?: return null
8
+ var explore: Node?
9
+ return if (node.right == null) {
10
+ explore = node
11
+ while (explore != null && explore == explore.parent?.right) explore = explore.parent
12
+ explore?.parent
13
+ } else {
14
+ explore = node.right
15
+ while (explore?.left != null) explore = explore.left
16
+ explore
17
+ }
18
19
20
+ class Node(var `val`: Int) {
21
+ var left: Node? = null
22
+ var right: Node? = null
23
+ var parent: Node? = null
24
25
+}
0 commit comments