Skip to content

Commit b5046ab

Browse files
committed
햄버거만들기(중급)
1 parent 818f307 commit b5046ab

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

unn04012/queue/hambuger.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(ingredients) {
2+
let answer = 0;
3+
const queue = [];
4+
5+
for (const ingredient of ingredients) {
6+
queue.push(ingredient);
7+
if (queue.length >= 4) {
8+
const hamburger = queue.slice(-4).join('');
9+
10+
if (hamburger === '1231') {
11+
answer++;
12+
for (let i = 0; i < 4; i++) queue.pop();
13+
}
14+
}
15+
}
16+
17+
return answer;
18+
}
19+
20+
console.log(solution([2, 1, 1, 2, 3, 1, 2, 3, 1]));

0 commit comments

Comments
 (0)