Created
October 28, 2015 22:53
-
-
Save chukitow/0b7df645891954eca8ed to your computer and use it in GitHub Desktop.
Given a String formed only by parenthesis check if they are well balanced (Every parenthesis that opens closes).
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
var stringGiven = "(()()(()))", | |
auxContainer = [], | |
finalContainer = []; | |
for(var i=0; i < stringGiven.length; i++){ | |
if(stringGiven[i] === "("){ | |
auxContainer.push(stringGiven[i]); | |
} | |
else{ | |
if(auxContainer.length){ | |
finalContainer.push(auxContainer.pop()); | |
finalContainer.push(stringGiven[i]); | |
} | |
} | |
} | |
console.log(finalContainer.join('').length === stringGiven.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment