Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 시뮬레이션
- priorityqueue
- SQL
- COS PRO
- 문자열
- 자바
- SWEA
- dfs
- Java
- 운동기록
- 러닝일지
- binary search
- BFS
- BOJ
- 문제해결
- db
- 이분탐색
- DP
- 알고리즘
- greedy
- math
- oracle
- 문제풀이
- 코딩테스트
- MySQL
- 건강
- 백준
- 프로그래머스
- 코테
- 투포인터
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 [1차] 캐시 본문


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/17680
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
public int solution(int cacheSize, String[] cities) {
int answer = 0;
Queue<String> q = new LinkedList<>();
for(int i=0;i<cities.length;i++){
String c = cities[i].toLowerCase();
if(q.contains(c)){
q.remove(c);
q.offer(c);
answer++;
continue;
}
else{
if(cacheSize!=0){
if(cacheSize==q.size()){
q.poll();
}
q.offer(c);
}
answer += 5;
}
}
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.2 전화번호 목록 (0) | 2025.10.15 |
|---|---|
| [프로그래머스] Lv.2 튜플 (0) | 2025.10.15 |
| [프로그래머스] Lv.2 기능개발 (0) | 2025.10.15 |
| [프로그래머스] Lv.2 피로도 (0) | 2025.10.15 |
| [프로그래머스] Lv.2 의상 (0) | 2025.10.15 |