fix(learn): Added solution for invert binary tree data structures challenge (#35922)

* fix: add solution for invert binary tree

* Fixed errors

* Used 2 spaces per request

* deleted images

* Update guide/english/certifications/coding-interview-prep/data-structures/invert-a-binary-tree/index.md

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* Update guide/english/certifications/coding-interview-prep/data-structures/invert-a-binary-tree/index.md

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* Update guide/english/certifications/coding-interview-prep/data-structures/invert-a-binary-tree/index.md

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* Update guide/english/certifications/coding-interview-prep/data-structures/invert-a-binary-tree/index.md

Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>

* fix: added extra line to avoid linting errors
This commit is contained in:
Stan Choi
2019-06-20 13:28:37 -04:00
committed by Manish Giri
parent 6f4a9ed721
commit a13d116aab
2 changed files with 81 additions and 10 deletions

View File

@ -39,14 +39,14 @@ tests:
```js
var displayTree = (tree) => console.log(JSON.stringify(tree, null, 2));
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
this.root = null;
// change code below this line
// change code above this line
}
```
@ -114,6 +114,28 @@ BinarySearchTree.prototype = {
<section id='solution'>
```js
// solution required
var displayTree = (tree) => console.log(JSON.stringify(tree, null, 2));
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
// change code below this line
this.invert = function(node = this.root) {
if (node) {
const temp = node.left;
node.left = node.right;
node.right = temp;
this.invert(node.left);
this.invert(node.right);
}
return node;
}
// change code above this line
}
```
</section>