https://school.programmers.co.kr/learn/courses/30/lessons/12909
function solution(s) {
let stack = [];
for (let i = 0; i < s.length; i++) {
if (s[i] === "(") {
stack.push(0);
} else {
if (stack.length !== 0) {
stack.pop();
} else {
return false;
}
}
}
let answer = stack.length === 0;
return answer;
}
function solution(s) {
let cnt = 0;
for (let x of s) {
x === "(" ? cnt++ : cnt--;
if (cnt < 0) return false;
}
return !cnt;
}