File tree Expand file tree Collapse file tree 3 files changed +63
-1
lines changed
0501-1000/0510-Inorder-Successor-in-BST-II/cpp-0510 Expand file tree Collapse file tree 3 files changed +63
-1
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.22 )
2
+ project (cpp_0510 )
3
+
4
+ set (CMAKE_CXX_STANDARD 14 )
5
+
6
+ add_executable (cpp_0510 main.cpp )
Original file line number Diff line number Diff line change
1
+ // / Source : https://leetcode.com/problems/inorder-successor-in-bst-ii/s
2
+ // / Author : liuyubobobo
3
+ // / Time : 2022-07-08
4
+
5
+ #include < iostream>
6
+ #include < vector>
7
+
8
+ using namespace std ;
9
+
10
+
11
+ // / Tree Algorithm
12
+ // / Time Compelxity: O(h)
13
+ // / Space Compelxity: O(1)
14
+
15
+ // Definition for a Node.
16
+ class Node {
17
+ public:
18
+ int val;
19
+ Node* left;
20
+ Node* right;
21
+ Node* parent;
22
+ };
23
+
24
+ class Solution {
25
+ public:
26
+ Node* inorderSuccessor (Node* node) {
27
+
28
+ if (node->right ){
29
+ return minimum (node->right );
30
+ }
31
+
32
+ Node* cur = node, *pre = node->parent ;
33
+ while (pre){
34
+ if (pre->left == cur){
35
+ return pre;
36
+ }
37
+ else {
38
+ cur = pre;
39
+ pre = cur->parent ;
40
+ }
41
+ }
42
+ return nullptr ;
43
+ }
44
+
45
+ private:
46
+ Node* minimum (Node* node){
47
+ while (node->left ) node = node->left ;
48
+ return node;
49
+ }
50
+ };
51
+
52
+
53
+ int main () {
54
+
55
+ return 0 ;
56
+ }
Original file line number Diff line number Diff line change @@ -539,7 +539,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
539
539
| 507 | [ Perfect Number] ( https://leetcode.com/problems/perfect-number/ ) | [ solution] ( https://leetcode.com/problems/perfect-number/solution/ ) | [ C++] ( 0501-1000/0507-Perfect-Number/cpp-0507/ ) | | |
540
540
| 508 | [ Most Frequent Subtree Sum] ( https://leetcode.com/problems/most-frequent-subtree-sum/ ) | [ 无] | [ C++] ( 0501-1000/0508-Most-Frequent-Subtree-Sum/cpp-0508/ ) | | |
541
541
| 509 | [ Fibonacci Number] ( https://leetcode.com/problems/fibonacci-number/ ) | [ 无] | [ C++] ( 0501-1000/0509-Fibonacci-Number/cpp-0509/ ) | | |
542
- | | | | | | |
542
+ | 510 | [ Inorder Successor in BST II ] ( https://leetcode.com/problems/inorder-successor-in-bst-ii/ ) | [ 无 ] | [ C++ ] ( 0501-1000/0510-Inorder-Successor-in-BST-II/cpp-0510/ ) | | |
543
543
| 511 | Database Problem: [ Link] ( https://github.com/liuyubobobo/Play-Leetcode-Database/ ) | - | - | - | - |
544
544
| | | | | | |
545
545
| 513 | [ Find Bottom Left Tree Value] ( https://leetcode.com/problems/find-bottom-left-tree-value/ ) | [ 无] | [ C++] ( 0501-1000/0513-Find-Bottom-Left-Tree-Value/cpp-0513/ ) | | |
You can’t perform that action at this time.
0 commit comments