Skip to content

Commit 02ec602

Browse files
committed
컨트롤_제트(기초)
1 parent 3e0c123 commit 02ec602

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

unn04012/stack/ctrl_z.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function solution(s) {
2+
const stack = [];
3+
let answer = 0;
4+
5+
s.split(' ').forEach((e) => {
6+
// 숫자가 아니면
7+
if (Number.isNaN(Number(e))) {
8+
answer -= stack.pop();
9+
} else {
10+
const num = Number(e);
11+
answer += num;
12+
stack.push(num);
13+
}
14+
});
15+
16+
return answer;
17+
}
18+
19+
console.log(solution('10 Z 20 Z'));

0 commit comments

Comments
 (0)