Created
July 19, 2019 01:50
-
-
Save RylanBauermeister/bc60a69b04100a5e9b245acac9e736a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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