You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//prevElement means the one previous to the current root, refer to in-order traversal, previous element must be smaller than the current root
33
-
//if it's bigger, then we find the first element, thus we store it in the variable called firstElement
34
-
if (firstElement == null && prevElement.val >= root.val) {
35
-
firstElement = prevElement;
36
-
}
37
+
//prevElement means the one previous to the current root, refer to in-order traversal, previous element must be smaller than the current root
38
+
//if it's bigger, then we find the first element, thus we store it in the variable called firstElement
39
+
if (firstElement == null && prevElement.val >= root.val) {
40
+
firstElement = prevElement;
41
+
}
37
42
38
-
if (firstElement != null && prevElement.val >= root.val) {
39
-
secondElement = root;
40
-
}
43
+
if (firstElement != null && prevElement.val >= root.val) {
44
+
secondElement = root;
45
+
}
41
46
42
-
//this is the last step in the "do some business logic", so we'll always to have update the previous node to be the current root before it traverses the right subtree
43
-
//since the current root will be the new previous node for the right subtree.
44
-
prevElement = root;
47
+
//this is the last step in the "do some business logic", so we'll always to have update the previous node to be the current root before it traverses the right subtree
48
+
//since the current root will be the new previous node for the right subtree.
0 commit comments