fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
This commit is contained in:
@@ -1,33 +1,28 @@
|
||||
---
|
||||
title: Invert a Binary Tree
|
||||
---
|
||||
## Invert a Binary Tree
|
||||
# Invert a Binary Tree
|
||||
|
||||
|
||||
---
|
||||
## Hints
|
||||
|
||||
## Hint: 1
|
||||
### Hint 1
|
||||
|
||||
Create a invert(node = this.root) method in the BinarySearchTree constructor function.
|
||||
|
||||
> _try to solve the problem now_
|
||||
|
||||
|
||||
## Hint: 2
|
||||
|
||||
Try to use recursion and think of a base case.
|
||||
|
||||
> _try to solve the problem now_
|
||||
|
||||
---
|
||||
## Solutions
|
||||
|
||||
## Spoiler Alert!
|
||||
|
||||
**Solution ahead!**
|
||||
|
||||
|
||||
## Basic Code Solution:
|
||||
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
||||
|
||||
```js
|
||||
var displayTree = (tree) => console.log(JSON.stringify(tree, null, 2));
|
||||
var displayTree = tree => console.log(JSON.stringify(tree, null, 2));
|
||||
function Node(value) {
|
||||
this.value = value;
|
||||
this.left = null;
|
||||
@@ -45,15 +40,13 @@ function BinarySearchTree() {
|
||||
this.invert(node.right);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
// change code above this line
|
||||
};
|
||||
// change code above this line
|
||||
}
|
||||
```
|
||||
|
||||
<a href='https://repl.it/repls/SereneScholarlyAnalyst' target='_blank' rel='nofollow'>Run Code</a>
|
||||
### Code Explanation:
|
||||
#### Code Explanation
|
||||
* Using recursion will allow you to traverse each node once and the only extra memory used is the auxiliary temp variable that enables you to swap. You keep swapping the left and right pointers of a node until you reach the leaves which will not do anything as the left and right of them are null references.
|
||||
## NOTES FOR CONTRIBUTIONS:
|
||||
**DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
|
||||
* Add an explanation of your solution.
|
||||
* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**.
|
||||
</details>
|
||||
|
||||
|
Reference in New Issue
Block a user