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 |
Tags
- 딕셔너리
- MYSQL
- 다이나믹 프로그래밍
- 스택
- 재귀
- 파이썬
- 그리디
- DP
- BOJ
- level0
- 브루트포스
- dfs
- BFS
- python
- 다익스트라
- level1
- level2
- level3
- dict
- 코딩테스트
- 운영체제
- 수학
- 힙
- 가상메모리
- 구현
- 백준
- 가상메모리 관리
- N과M
- programmers
- 프로그래머스
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [1차 캐시] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/17680
코딩테스트 연습 - [1차] 캐시
3 ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "Jeju", "Pangyo", "Seoul", "NewYork", "LA"] 50 3 ["Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul", "Jeju", "Pangyo", "Seoul"] 21 2 ["Jeju", "Pangyo", "Seoul", "NewYork", "LA", "SanFrancisco", "Seoul", "Ro
programmers.co.kr
#프로그래머스 [1차] 캐시
def solution(cacheSize, cities):
answer = 0
for i in range(len(cities)):
cities[i]=cities[i].upper()
lst=[]
for i in range(len(cities)):
if cities[i] in lst:
ind=lst.index(cities[i])
lst.append(lst.pop(ind))
answer+=1
else:
lst.append(cities[i])
if len(lst)>cacheSize:
lst.pop(0)
answer+=5
return answer
캐시를 lst에 담는다. city가 lst(캐시)에 존재하면, 캐시의 맨끝으로 city를 옮긴다.
존재하지 않으면, 캐시에 삽입한다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [방문 길이] 파이썬 (0) | 2021.12.09 |
---|---|
프로그래머스 level2 [ [3차] 파일명 정렬] 파이썬 (0) | 2021.12.09 |
프로그래머스 level2 [구명보트] 파이썬 (0) | 2021.12.08 |
프로그래머스 level2 [가장 큰 수] 파이썬 (0) | 2021.12.08 |
프로그래머스 level2 [가장 큰 정사각형 찾기] 파이썬 (0) | 2021.12.08 |