Leetcode#450. Delete Node in a BST
ProblemGiven a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.
Basically, the deletion can be divided into two stages:
Search for a node to remove.
If the node is found, delete the node.
Example 1:
!https://assets.leetcode.com/uploads/2020/09/04/del_node_1.jpg
123456Input: root = [5,3,6,2,4,null,7], key = 3Output: [5,4,6,2,null,null,7]Explanation: Given key to delete is 3. So we find the node ...
Leetcode#530. Minimum Absolute Difference in BST
ProblemGiven the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.
Example 1:
!https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg
123Input: root = [4,2,6,1,3]Output: 1
Example 2:
!https://assets.leetcode.com/uploads/2021/02/05/bst2.jpg
123Input: root = [1,0,48,null,null,12,49]Output: 1
Constraints:
The number of nodes in the tree is in the range [2, 10^4].
0 <= Node.val <= 10^5
Solve法一由於有有序性質、且正整 ...