Step 1:
Use the key to find this node in BST, time complexity is log(n)
Step 2:
after finding this node, we have 3 different conditions:
1, if this node‘s left and right children are null, just set this node‘s parent‘s link to this to null;
2, if this node only has one child, just replace this node with it‘s child;
3, if this node has two children, then we need to find the minimum key node in this node‘s right subtree, then replace this node with the minimum key node, then delete this minimum key node in the right subtree.
时间: 2024-10-09 09:03:28