Title: Delete Node in a Binary Search Tree
Description:
Given a binary search tree and a value key, delete the node corresponding to key in the binary search tree, and restore it using its right child, as shown in the diagram below, while maintaining the properties of the binary search tree. Return the level order traversal of the binary search tree (including all nodes of the complete binary tree representation of this tree, with missing nodes represented by null).
Generally, deleting a node can be divided into two steps:
First, find the node to be deleted.
If found, delete it.
Input:
The level order traversal of the binary search tree (including all nodes of the complete binary tree representation of this tree, with missing nodes represented by null) and the node to be deleted.
Output:
The level order traversal of the binary search tree after deletion (including all nodes of the complete binary tree representation of this tree, with missing nodes represented by null).
Sample Input 1:
5,3,6,2,4,null,7
3
Sample Output 1:
5,4,6,2,null,null,7
Sample Input 2:
5,3,6,2,4,null,7
0
Sample Output 2:
5,3,6,2,4,null,7
Not the question you are looking for? Ask here!
Enter question by text
Enter question by image
Unlock Smarter Learning with AskSia Super!
Join Super, our all-in-one AI solution that can greatly improve your learning efficiency.