Example:
"()" | "()[]{}" | "{[]}" true {{{{}}}([])}
"(]" | "([)]" false {{{{}}}([[])]} {([)]}
*/
var str = "{{{{}}}([[])]}";
var isValid = function(s){
let items = []
let sLength = s.length
if(sLength % 2 !== 0){
return false
}
for(let i=0; i < sLength; i++){
switch(s[i]){
case "(":
items.push(s[i])
break
case "[":
items.push(s[i])
break
case "{":
items.push(s[i])
break
case ")":
if(items[items.length - 1] === "("){
items.pop()
}
break
case "]":
if(items[items.length - 1] === "["){
items.pop()
}
break
case "}":
if(items[items.length - 1] === "{"){
items.pop()
}
break
}
}
return items.length === 0
}
console.log(isValid(str))
Read More:
- JavaScript determines whether it’s morning or afternoon or evening
- Javascript: Simple package localStorge operation
- JavaScript Common Errors List (Reasons & Solutions)
- [Solved] Vue Compile Error: JavaScript heap out of memory
- Google browser plug-in JavaScript errors Notifier
- Javascript: js websocket disconnected reconnect library ReconnectingWebSocket
- Error when Python executes JavaScript statement
- [Solved] Project Package Error: Javascript heap out of memory
- [Solved] VS Code Debug JavaScript Error: “crbug/1173575, non-JS module files deprecated”
- Javascript: How to Use Date.Now() to implement front-end frequency limit
- Javascript SecurityError: Failed to read the’localStorage’ property from’Window’: Access is denied for this document.
- ArcGIS API for JavaScript Error Uncaught(in promise): TypeError: xxx is not a constructor
- [Solved] Vue Project Modify Page Error: CALL_AND_RETRY_LAST Allocation failed – JavaScript heap out of memory
- ArcGIS API for JavaScript version 4. X updated and the project startup error: Module parse failed: Unexpected token(… …
- [Solved] Vite Error: Failed to load module script: Expected a JavaScript module script but the server…
- [Solved] Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory
- [Solved] react-router-dom Error: index.js:1 Warning: Functions are not valid as a React child.
- [Solved] Some chunks are bigger warning on vite packaging
- [Solved] Vite packing error: some chunks are larger than 500kb after minification
- [Solved] Error:Plugin/Preset files are not allowed to export objects, only functions