/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
// Solution is from http://rainykat.blogspot.com/2017/01/leetcodeuber-450-delete-node-in-bstdfs.html
// We have 4 scenarios in general:
// 1. Root is Null -> return null
// 2. Root.val is greater than key -> we search key in the left tree.
// 3. Root.val is less than key -> we search key in the right tree.
// 4. Root.val the same with key:
//    4.1 if root.left is null, then we return root.right
//    4.2 if root.right is null, then we return root.left
//    4.3 otherwise, we find the first successor of root, replace roots val with successor.val,
//        and remove successor using recursion.
class Solution {
    public TreeNode deleteNode(TreeNode root, int key) {
        if (root == null) {
            return null;
        }
        
        if (root.val > key) {
            root.left = deleteNode(root.left, key);
            return root;
        } else if (root.val < key) {
            root.right = deleteNode(root.right, key);
            return root;
        } else {
            if (root.left == null) {
                return root.right;
            } else if (root.right == null) {
                return root.left;
            } else {
                TreeNode successor = findSuccessor(root.right);
                root.val = successor.val;
                root.right = deleteNode(root.right, successor.val);
                return root;
            }
        }
    }
    
    private TreeNode findSuccessor(TreeNode root) {
        TreeNode p = root;
        while (p.left != null) {
            p = p.left;
        }
        
        return p;
    }
}

@@ -172,610 +172,8 @@
  */%0A
-// Solution is from http://rainykat.blogspot.com/2017/01/leetcodeuber-450-delete-node-in-bstdfs.html%0A// We have 4 scenarios in general:%0A// 1. Root is Null -%3E return null%0A// 2. Root.val is greater than key -%3E we search key in the left tree.%0A// 3. Root.val is less than key -%3E we search key in the right tree.%0A// 4. Root.val the same with key:%0A//    4.1 if root.left is null, then we return root.right%0A//    4.2 if root.right is null, then we return root.left%0A//    4.3 otherwise, we find the first successor of root, replace roots val with successor.val,%0A//        and remove successor using recursion.%0A
 clas
@@ -400,33 +400,8 @@
 y);%0A
-            return root;%0A
     
@@ -483,41 +483,16 @@
 ight
-,
  
+,
 key);%0A
-            return root;%0A
     
@@ -696,42 +696,26 @@
     
-TreeNode successor = findSuccessor
+root.val = findMin
 (roo
@@ -744,33 +744,8 @@
     
-root.val = successor.val;
 %0A   
@@ -797,17 +797,12 @@
 ht, 
-successor
+root
 .val
@@ -820,48 +820,49 @@
     
-    return root;%0A            %7D%0A        %7D
+%7D%0A        %7D%0A        %0A        return root;
 %0A   
@@ -885,30 +885,19 @@
 ate 
-TreeNode findSuccessor
+int findMin
 (Tre
@@ -902,20 +902,17 @@
 reeNode 
-root
+p
 ) %7B%0A    
@@ -919,26 +919,8 @@
     
-TreeNode p = root;
 %0A   
@@ -1008,16 +1008,20 @@
 return p
+.val
 ;%0A    %7D%0A

Update DeleteNodeInBST.java