Skip to content

Instantly share code, notes, and snippets.

@RylanBauermeister
Created July 19, 2019 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RylanBauermeister/bc60a69b04100a5e9b245acac9e736a0 to your computer and use it in GitHub Desktop.
Save RylanBauermeister/bc60a69b04100a5e9b245acac9e736a0 to your computer and use it in GitHub Desktop.
//If it has only a right child, we replace the node we are deleting with its child.
else if (node.right && !node.left){
let right = node.right;
node.val = right.val;
node.left = right.left;
node.right = right.right;
if(node.right) node.right.parent = node;
if(node.left) node.left.parent = node;
right = null;
return true;
}
//Same for only on the left
else if (!node.right && node.left){
let left = node.left;
node.val = left.val;
node.right = left.right;
node.left = left.left;
if(node.right) node.right.parent = node;
if(node.left) node.left.parent = node;
left = null;
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment