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,25 +1,24 @@
|
||||
---
|
||||
title: Balanced brackets
|
||||
---
|
||||
## Balanced brackets
|
||||
# Balanced brackets
|
||||
|
||||
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/coding-interview-prep/rosetta-code/balanced-brackets/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
|
||||
|
||||
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
|
||||
---
|
||||
## Solutions
|
||||
|
||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||
<details><summary>### Solution #1 (Click to Show/Hide)</summary>
|
||||
|
||||
### Basic Solution
|
||||
```js
|
||||
function isBalanced(str) {
|
||||
if (str === '') return true;
|
||||
if (str === "") return true;
|
||||
|
||||
str = str.split('');
|
||||
str = str.split("");
|
||||
let stack = [];
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
if (str[i] === '[') {
|
||||
stack.push('[');
|
||||
} else if (str[i] === ']' && stack[stack.length - 1] === '[') {
|
||||
if (str[i] === "[") {
|
||||
stack.push("[");
|
||||
} else if (str[i] === "]" && stack[stack.length - 1] === "[") {
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
@@ -32,3 +31,5 @@ function isBalanced(str) {
|
||||
- Push every `[` into a stack.
|
||||
- Check if the item stored on the stack is `[` when a `]` occurs. This makes it a pair & `[` can be removed from the stack.
|
||||
- The brackets are balanced if there is no item present in the stack.
|
||||
|
||||
</details>
|
||||
Reference in New Issue
Block a user