- 난이도: Lv2
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/131127
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/2/할인 행사
풀이 시간 : 1시간 25분
import java.util.*;
class Solution {
public int solution(String[] want, int[] number, String[] discount) {
int answer = 0;
for (int i = 0; i <= discount.length - 10; i++) {
Map<String, Integer> countMap = new HashMap<>();
for (int j = i; j < i + 10; j++) {
countMap.put(discount[j], countMap.getOrDefault(discount[j], 0) + 1);
}
boolean isValid = true;
for (int j = 0; j < want.length; j++) {
if (countMap.getOrDefault(want[j], 0) < number[j]) {
isValid = false;
break;
}
}
if (isValid) answer++;
}
return answer;
}
}