GoConqr has a new look! Let us know what you think.

Flashcards

Delete Node in a BST

Suhas S English 1 card

Cards in this deck (1)

  1. 1Delete Node in a BSTclass Solution {
    public TreeNode deleteNode(TreeNode root, int key) {
    if(root == null) return root;
    if(key < root.val){
    root.left = deleteNode(root.left,key);
    }else if(key > root.val){
    root.right = deleteNode(root.right, key);
    }else{
    if(root.left == null) return root.right;
    else if(root.right == null) return root.left;
    TreeNode minNode = findMin(root.right);
    root.val = minNode.val;
    root.right = deleteNode(root.right, root.val);
    }
    return root;
    }
    private TreeNode findMin(TreeNode node){
    while(node.left!=null) node = node.left;
    return node;
    }
    }

Information

Description
Flashcards on Delete Node in a BST, created by Suhas S on 16/02/2018.
Created by
Suhas S
Views
9
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?