/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
var stack= [];
var sArr= s.split("");
var symObj= {"}": "{", "]": "[", ")":")"};
while(sArr.length){
var head= sArr.shift();
switch(head){
case '(':
case '{':
case '[':
stack.push(head);
break;
case ')':
case '}':
case ']':
if(stack.pop() !== symObj[head]){
return false;
}
break;
}
}
return stack.length === 0
};
网友评论