forked from azl397985856/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
简单LeetCode 难度定级LeetCode 难度定级
Description
/**
* @param {string} s
* @return {boolean}
*/
var isValid = function (s) {
const stack = []; // 使用栈存储遇到的字符
for (let i = 0; i < s.length; i++) {
const top = stack[stack.length - 1];
if ((s[i] === ')' && top === '(') || (s[i] === '}' && top === '{') || (s[i] === ']' && top === '[')) {
stack.pop();
} else {
stack.push(s[i]);
}
}
return !stack.length;
};
Metadata
Metadata
Assignees
Labels
简单LeetCode 难度定级LeetCode 难度定级