Skip to content

Commit 582aea8

Browse files
authored
Update Delete Node in a BST.java
1 parent e1f30a9 commit 582aea8

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Medium/Delete Node in a BST.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ public TreeNode deleteNode(TreeNode root, int key) {
2020
}
2121
if (root.val > key) {
2222
root.left = deleteNode(root.left, key);
23-
}
24-
else if (root.val < key) {
23+
} else if (root.val < key) {
2524
root.right = deleteNode(root.right, key);
26-
}
27-
else {
25+
} else {
2826
if (root.left == null || root.right == null) {
2927
TreeNode temp = root.left == null ? root.right : root.left;
3028
return temp;
31-
}
32-
else {
29+
} else {
3330
TreeNode inorderSuccessor = root.right;
3431
while (inorderSuccessor.left != null) {
3532
inorderSuccessor = inorderSuccessor.left;

0 commit comments

Comments
 (0)