3
TreeNode *deleteNode(TreeNode *root, int key) {6
root->left = deleteNode(root->left, key); // We frecursively call the function7
// until we find the target node8
else if (key > root->val)9
root->right = deleteNode(root->right, key);11
if (!root->left && !root->right) return NULL; // No child condition12
if (!root->left || !root->right)13
return root->left ? root->left : root->right; // One child contion -> replace the node14
// with it's child Two child condition15
TreeNode *temp = root->left; //(or) TreeNode *temp = root->right;16
while (temp->right != NULL)17
temp = temp->right; // while(temp->left != NULL) temp = temp->left;18
root->val = temp->val; // root->val = temp->val;19
root->left = deleteNode(root->left,20
temp->val); // root->right = deleteNode(root->right, temp);