Skip to content

Commit 94221e5

Browse files
committed
Burger making / 중급
1 parent c90945b commit 94221e5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// https://school.programmers.co.kr/learn/courses/30/lessons/133502
2+
3+
function solution(ingredient) {
4+
let stack = [];
5+
let result = 0;
6+
for (let i = 0; i < ingredient.length; i++) {
7+
let item = ingredient[i];
8+
stack.push(item);
9+
if (stack.length >= 4) {
10+
let last4 = stack.slice(-4);
11+
if (last4.join("") === "1231") {
12+
result++;
13+
stack.splice(-4);
14+
}
15+
}
16+
}
17+
return result;
18+
}

0 commit comments

Comments
 (0)