-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_133502.java
More file actions
28 lines (26 loc) · 740 Bytes
/
_133502.java
File metadata and controls
28 lines (26 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
class Solution {
public int solution(int[] ingredient) {
Stack<Integer> S = new Stack<>();
int answer = 0;
for(int element : ingredient){
if(element==1 && S.size()>=3){
if(S.peek()==3){
S.pop();
if(S.peek()==2){
S.pop();
if(S.peek()==1){
S.pop();
answer++;
continue;
}
S.push(2);
}
S.push(3);
}
}
S.add(element);
}
return answer;
}
}