Open tsungtingdu opened 3 years ago
var isValid = function(s) { let sets = { '(' : ')', '{' : '}', '[' : ']' } let stack = [] for (let i = 0; i < s.length; i++) { if (s[i] in sets) { stack.push(s[i]) // find left } else { let temp = stack.pop() if (sets[temp] !== s[i]) return false } } return stack.length === 0 };