leetcode 20. Valid Parentheses
作者:
_呆瓜_ | 来源:发表于
2017-04-05 01:00 被阅读13次/**
* @param {string} s
* @return {boolean}
*/
var isValid = function(s) {
if (s===undefined) {
return false;
}
if (s === '') {
return true;
}
var stack = [];
for (var i = 0; i < s.length; i++) {
//var l = stack.length;
var c = stack.pop();
var temp = s[i];
if (c === undefined) {
stack.push(temp);
} else {
if ((c === '(' && temp === ')')
|| (c === '[' && temp === ']')
|| (c === '{' && temp === '}')) {
//stack.pop();
} else {
stack.push(c);
stack.push(temp);
}
}
}
if (stack.length == 0) {
return true;
} else {
return false;
}
};
本文标题:leetcode 20. Valid Parentheses
本文链接:https://www.haomeiwen.com/subject/ouqtattx.html
网友评论