Skip to content

mmacdonald1/balanced-brackets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

balanced-brackets

Today we are going to introduce a new multipurpose data structure. A stack is an Array. When we interact with this array, we will only use the .push and .pop methods.

let stack = [];

stack.push("{") // [{]

stack.push("(") // [{,(]

stack.pop(")") // [{]

This last-in-first-out paradigm does not come up in everyday programming, but can be very helpful for specific use cases such as the following problem.

Given a string containing (), [], and/or {} write a program that returns true or false if the string is balanced. Balanced is defined as having no unmatched brackets and if there are brackets inside the current brackets, those brackets are an opening and closing pair.

Example:

{[()]} - Balanced

{[(])} - Not Balanced

{adf}() - Balanced

)( - Not Balanced

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published