-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
Description
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
var arr = [];
s = s.split('');
for(var i=0;i<s.length;i++){
if(s[i] == "(" || s[i] == "[" || s[i] == "{"){
arr.push(s[i])
}
if(s[i] == ")"){
if(arr[arr.length-1] == "("){
arr.pop();
}else{
return false
}
}
if(s[i] == "]"){
if(arr[arr.length-1] == "["){
arr.pop();
}else{
return false
}
}
if(s[i] == "}"){
if(arr[arr.length-1] == "{"){
arr.pop();
}else{
return false
}
}
}
if(arr.length>0){
return false;
}
return true;
};
LeetCode原题链接:https://leetcode-cn.com/problems/valid-parentheses/description/
