Yeah, I just refactored a bit ``` fun deleteNode(r...
# codereview
c
Yeah, I just refactored a bit
Copy code
fun deleteNode(root: BinaryTreeNode<T>?, value: T): BinaryTreeNode<T>? {
    var troot: BinaryTreeNode<T> = root ?: return null
    when {
      troot.data > value -> troot.leftChild = deleteNode(troot.leftChild, value)
      troot.data < value -> troot.rightChild = deleteNode(troot.rightChild, value)
      else -> {
        when {
          troot.leftChild != null && troot.rightChild != null -> {
            val temp = troot
            val inOrderSuccessor = temp.rightChild?.getMinimum()
            troot.data = inOrderSuccessor?.data!!
            deleteNode(troot.rightChild, inOrderSuccessor.data)
          }
          troot.leftChild != null -> troot = troot.leftChild!!
          troot.rightChild != null -> troot = troot.rightChild!!
          else -> return null
        }
      }
    }
    return troot
  }