반응형
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
- 에라스토테네스의 체
- N과M
- BOJ
- programmers
- level3
- 코딩테스트
- level2
- 가상메모리
- BFS
- 그리디
- 투포인터
- python
- DP
- 딕셔너리
- 구현
- 프로그래머스
- level1
- 백준
- 파이썬
- 다이나믹 프로그래밍
- 스택
- 가상메모리 관리
- 운영체제
- 힙
- 다익스트라
- dfs
- MYSQL
- 수학
- 재귀
- 브루트포스
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 |