Day 25: force buckle question 20, valid brackets
Address: leetcode-cn.com/problems/va…
The first open parenthesis matching the first open parenthesis matching the first open parenthesis matching the first open parenthesis matching the first open parenthesis matching.
var isValid = function(s) { s.split(""); let res = []; let object = { '(':')', '[':']', '{':'}' } for(let i = 0; i < s.length; i++) { if(s[i] == '(' ||s[i] == '['||s[i] == '{') { res.unshift(s[i]); } else{ if(object[res.shift()] ! = s[i]) { return false; } } } if(res.length == 0) { return true; } else{ return false; } };Copy the code
Execution time: 84 ms, beating 75.44% of all JavaScript commits
Memory consumption: 37.8 MB, beating 34.20% of all JavaScript commits