285 Inorder Successor in BST
285. Inorder Successor in BST
1. Question
Given a binary search tree and a node in it, find the in-order successor of that node in the BST.
Note: If the given node has no in-order successor in the tree, returnnull
.
2. Implementation
(1) Inorder traversal
(2) Binary Search
思路: 利用Binary Search Tree的二分特性
3. Time & Space Complexity
Inorder Traversal: 时间复杂度: O(n), 空间复杂度: O(h)
Binary Search: 时间复杂度: O(logn), 空间复杂度: O(1)
Last updated