var isValid = function (s) {
const stack = []
for (const e of s) {
if (e === '(' || e === '[' || e === '{') {
stack.push(e)
}
if (e === ')' || e === ']' || e === '}') {
const pre = stack.pop()
const val = `${pre}${e}`
if (val === '()' || val === '{}' || val === '[]') {
continue
} else {
return false
}
}
}
if (stack.length > 0) {
return false
}
return true
};