Skip to content

Commit

Permalink
#18 23.08.31 > 4 > 좋은 단어
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Aug 31, 2023
1 parent 0100613 commit 2567eb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/bj/silver/4/3986.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

/**
* [stack, 수식의 괄호쌍 문제]
*/

const [N, ...arr] = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n");

const solution = (N, arr) => {
let answer = 0;

for (let i = 0; i < N; i++) {
const stack = [];
const str = arr[i].split("");

for (let j = 0; j < str.length; j++) {
const top = stack[stack.length - 1];
const now = str[j];
if (top === now) stack.pop();
else stack.push(now);
}

answer = stack.length ? answer : answer + 1;
}
return answer;
};

console.log(solution(+N, arr));
1 change: 1 addition & 0 deletions src/bj/silver/4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@
| 35 | 10825 | [국영수](./10825.js) | 23.06.06 ||
| 36 | 2870 | [수학숙제](./2870.js) | 23.06.11 ||
| 37 | 2847 | [게임을 만든 동준이](./2847.js) | 23.06.12 | X |
| 38 | 3986 | [좋은 단어](./3986.js) | 23.08.31 | O |

0 comments on commit 2567eb6

Please sign in to comment.