Skip to content

Commit d2ea748

Browse files
authored
Merge pull request #1625 from AlgorithmWithGod/LiiNi-coder
[20251209] PGM / LV2 / 할인 행사 / 이인희
2 parents 69ddf7b + c991046 commit d2ea748

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
private static HashMap<String, Integer> wordsIndex;
6+
7+
public int solution(String[] wants, int[] number, String[] discounts) {
8+
int answer = 0;
9+
wordsIndex = new HashMap<String, Integer>();
10+
int i = 0;
11+
for(String want : wants){
12+
wordsIndex.put(want, i++);
13+
}
14+
int[] counts = new int[wants.length];
15+
16+
ArrayDeque<String> q = new ArrayDeque<String>();
17+
String polled;
18+
for(String discount : discounts){
19+
if(wordsIndex.containsKey(discount)){
20+
counts[wordsIndex.get(discount)]++;
21+
}
22+
q.offer(discount);
23+
if(q.size() > 10){
24+
polled = q.poll();
25+
if(wordsIndex.containsKey(polled)){
26+
counts[wordsIndex.get(polled)]--;
27+
}
28+
}
29+
30+
if(q.size() == 10){
31+
boolean ok = true;
32+
for(int k=0; k<number.length; k++){
33+
if(counts[k] < number[k]){
34+
ok = false;
35+
break;
36+
}
37+
}
38+
if(ok){
39+
answer++;
40+
}
41+
}
42+
}
43+
44+
return answer;
45+
}
46+
}
47+
48+
```

0 commit comments

Comments
 (0)