Jul 16, 2024
function deleteNode(root, key):
if root is None:
return root
if key < root.value:
root.left = deleteNode(root.left, key)
elif key > root.value:
root.right = deleteNode(root.right, key)
else:
if root.left is None:
return root.right
elif root.right is None:
return root.left
temp = minValueNode(root.right)
root.value = temp.value
root.right = deleteNode(root.right, temp.value)
return root