Skip to content

Commit 8e5ce6e

Browse files
authored
Merge pull request #1193 from AlgorithmWithGod/lkhyun
[20251022] PGM / Lv2 / [1차]캐시 / 이강현
2 parents cd58ef6 + 7f1a0d8 commit 8e5ce6e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```java
2+
import java.util.*;
3+
class Solution {
4+
public int solution(int cacheSize, String[] cities) {
5+
int answer = 0;
6+
List<String> cache = new LinkedList<>();
7+
8+
for(String c : cities){
9+
String city = c.toLowerCase();
10+
if(cache.contains(city)){
11+
cache.remove(city);
12+
cache.add(city);
13+
answer++;
14+
}else{
15+
cache.add(city);
16+
answer+=5;
17+
}
18+
if(cache.size() > cacheSize){
19+
cache.remove(0);
20+
}
21+
}
22+
return answer;
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)