// 说明
function isValid (str) {
if (str.length % 2 !== 0) return false
const stack = []
// 遍历
for (let i = 0; i < str.length; i++) {
const s = str[i]
if (s === '(' || s === '[' || s === '{') {
stack.push(s)
} else {
const t = stack[stack.length - 1]
if ((t === '(' && s === ')') || (t === '[' && s === ']') || (t === '{' && s === '}')) {
stack.pop()
} else {
return false
}
}
}
return stack.length === 0
}