https://leetcode.com/problems/valid-parentheses/
Valid parentheses
Given A string containing just the characters,,, ‘(‘ ‘)‘ , and ‘{‘ ‘}‘ ‘[‘ ‘]‘ , determine if the input string I S valid.
The brackets must close in the correct order, and is all valid but and is not "()" "()[]{}" "(]" "([)]" .
The water problem is very pleasant.
1 /**2 * @param {string} s3 * @return {Boolean}4 */5 varIsValid =function(s) {6 varstack = [];7 functionbrackets (left, right) {8 if(left = = = ' (' && right = = = ') '){9 return true;Ten}Else if(left = = = ' [' && right = = = '] '){ One return true; A}Else if(left = = ' {' && right = = = '} '){ - return true; - } the return false; - } - vartop =NULL; - for(varIinchs) { + if(/[\({\[]/. Test (S[i])) { - Stack.push (S[i]); +}Else{ A if(Stack.length > 0){ attop =Stack.pop (); - if(!brackets (top, s[i])) { - return false; - } -}Else{ - return false; in } - } to } + - if(stack.length!== 0){ the return false; * } $ return true;Panax Notoginseng};
[Leetcode] [JavaScript] Valid parentheses