Skip to content

Commit 8b2f46f

Browse files
committed
햄버거 만들기 / 중급
1 parent 3ed157c commit 8b2f46f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function solution(ingredient) {
2+
let stack = [];
3+
let count = 0;
4+
let i = 0;
5+
6+
while(i < ingredient.length) {
7+
stack.push(ingredient[i]);
8+
9+
if(stack.length >= 4) {
10+
const len = stack.length;
11+
if(stack[len-4] === 1 &&
12+
stack[len-3] === 2 &&
13+
stack[len-2] === 3 &&
14+
stack[len-1] === 1) {
15+
stack.splice(-4);
16+
count++;
17+
}
18+
}
19+
i++;
20+
}
21+
22+
return count;
23+
}
24+
25+
// function solution(ingredient) {
26+
// let queue = [...ingredient];
27+
// let stack = [];
28+
// let count = 0;
29+
30+
// while(queue.length > 0) {
31+
// stack.push(queue.shift());
32+
33+
// if(stack.length >= 4) {
34+
// const len = stack.length;
35+
// if(stack[len-4] === 1 &&
36+
// stack[len-3] === 2 &&
37+
// stack[len-2] === 3 &&
38+
// stack[len-1] === 1) {
39+
// stack.splice(-4);
40+
// count++;
41+
// }
42+
// }
43+
// }
44+
45+
// return count;
46+
// }

0 commit comments

Comments
 (0)