문제: 올바른 괄호, 짝이 맞으면 "yes", 괄호의 짝이 안맞으면 "no"를 출력한다.
입력) () 소괄호 / (()) => 짝이 맞다 / (()))) => 짝이 맞지 않다
function solution(arr) {
let stack = [];
for (let el of arr) {
if (el === "(") {
stack.push(el);
} else {
if (stack.length === 0) {
return "no";
} else {
stack.pop();
}
}
if (stack.length > 0) {
return "no";
}
return "yes";
}
}
let arr = "(()(()))(()"; // no
console.log(solution(arr));