Skip to content

Instantly share code, notes, and snippets.

@youngvctr
Created August 22, 2023 17:58
Show Gist options
  • Save youngvctr/409a320e654d701f97a79a0e4eda0099 to your computer and use it in GitHub Desktop.
Save youngvctr/409a320e654d701f97a79a0e4eda0099 to your computer and use it in GitHub Desktop.
Programmers | 할인 행사
import java.util.Map;
import java.util.HashMap;
class Solution {
public int solution(String[] want, int[] number, String[] discount) {
int answer = 0;
Map<String, Integer> wantMap = new HashMap<>();
Map<String, Integer> discountMap = new HashMap<>();
for(int i=0; i<want.length; i++){
wantMap.put(want[i], number[i]);
}
for(int i=0; i<discount.length-10+1; i++){
discountMap = new HashMap<>();
for(int j=i; j<i+10; j++){
discountMap.put(discount[j], discountMap.getOrDefault(discount[j], 0) + 1);
}
int count = 0;
for(int j=0; j<want.length; j++){
if(discountMap.containsKey(want[j])){
if(wantMap.get(want[j]) <= discountMap.get(want[j])){
count++;
}
}
}
if(count == want.length) answer++;
}
return answer;
}
}
@youngvctr
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment