Created
September 7, 2017 18:21
-
-
Save Smakar20/74f73067750ce5c6837514029394f601 to your computer and use it in GitHub Desktop.
null created by smakar20 - https://repl.it/KoQp/0
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
/*Have the function RemoveBrackets(str) take the str string parameter being passed, which will contain only the characters "(" and ")", and determine the minimum number of brackets that need to be removed to create a string of correctly matched brackets. For example: if str is "(()))" then your program should return the number 1. The answer could potentially be 0, and there will always be at least one set of matching brackets in the string.*/ | |
(function RemoveBrackets(str) { | |
let tempArr = [] | |
for(let i = 0; i < str.length; i++){ | |
if(tempArr[tempArr.length-1] === '(' && str[i] === ')'){ | |
tempArr.pop() | |
}else{ | |
tempArr.push(str[i]) | |
} | |
} | |
return tempArr.length | |
}(')()(()()')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment