[programmers][X] [1차] 캐시
in Algorithm on Algorithm
https://school.programmers.co.kr/learn/courses/30/lessons/17680
import java.util.*;
class Solution {
public int solution(int cacheSize, String[] cities) {
int answer = 0;
Queue<String> q = new ArrayDeque<>();
for(String city : cities){
if(q.size() > cacheSize) q.poll();
city = city.toLowerCase();
if(q.contains(city)){
q.remove(city);
answer += 1;
}else{
answer += 5;
}
q.offer(city);
}
return answer;
}
}