Skip to content

Commit

Permalink
짝지어 제거하기
Browse files Browse the repository at this point in the history
  • Loading branch information
dudwns committed Jun 17, 2023
1 parent 5a9340a commit 0a25686
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Programmers/exam90.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function solution(s) {
const stack = [];
for (let i = 0; i < s.length; i++) {
if (!stack.length || stack[stack.length - 1] !== s[i]) {
stack.push(s[i]); // 스택이 비어있거나, 이전 문자가 현재 문자와 다를 때 stack에 push
} else {
stack.pop(); // 이전 문자열이랑 같으면 pop
}
}

return stack.length ? 0 : 1; // 스택이 비어있으면 성공했다는 뜻이므로 1을 리턴, 아니면 0을 리턴
}

0 comments on commit 0a25686

Please sign in to comment.