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
- 직원 이직률
- 삼성SDS Brightics
- 삼성SDS Brigthics
- 브라이틱스
- Brightics를 이용한 분석
- 혼공학습단
- 브라이틱스 서포터즈
- 삼성 SDS Brigthics
- 포스코 청년
- 영상제작기
- 추천시스템
- 삼성 SDS
- Brightics Studio
- 삼성SDS
- 노코드AI
- 데이터분석
- Brigthics
- 혼공머신러닝딥러닝
- 혼공
- 직원 이직여부
- Brightics
- 포스코 아카데미
- 혼공머신
- Brigthics Studio
- 개인 의료비 예측
- Brigthics를 이용한 분석
- 모델링
- 팀 분석
- 데이터 분석
- 캐글
Archives
- Today
- Total
데이터사이언스 기록기📚
[프로그래머스] Level 2_[1차]캐시(2018 KAKAO BLIND RECRUITMENT) 본문
Coding Test/프로그래머스(Python)
[프로그래머스] Level 2_[1차]캐시(2018 KAKAO BLIND RECRUITMENT)
syunze 2022. 10. 13. 12:36📌문제 유형
2018 KAKAO BLIND RECRUITMENT
📌문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
- LRU 알고리즘이란?
LRU 알고리즘 (Least Recentely Used) 개념 및 구현방법
안녕하세요! daily_D 입니다! 👩🏻💻 오늘은 페이지 교체 알고리즘 중에서 LRU에 대해서 공부해볼까요?! LRU 란? LRU(Least Recently Used)는 가장 오랫동안 참조되지 않은 페이지를 교체하는 방식입니
dailylifeofdeveloper.tistory.com
📌나의 문제풀이
- cities : city는 대소문자 구분하지 않아 lower로 통일
- cachesize == 0일때는 크기만큼 리턴
- cacheSize보다 작을 때, 같을 때 고려하기
def solution(cacheSize, cities):
answer = 0
cities = [city.lower() for city in cities]
visit = []
if cacheSize == 0:
return 5 * len(cities)
for city in cities:
# cacheSize보다 작을 때
if len(visit) < cacheSize:
if city not in visit:
visit.append(city)
answer += 5
else:
visit.remove(city) # visit에 있으면 삭제 후
visit.append(city) # 뒤에 다시 넣기
answer += 1
# cacheSize랑 같을 때
else:
if city not in visit:
visit.append(city)
answer += 5
visit.pop(0) # cacheSize 맞추기위해 삭제
else:
visit.remove(city)
visit.append(city)
answer += 1
return answer
📌다른 사람들의 문제풀이
1) deque의 maxlen 사용
- maxlen
[Python] deque 기본 설정( deque(iterable, maxlen) )
deque를 쓸 때 다음과 같이 모듈을 불러온다. from collections import deque deque를 from queue import deque로 불러올 수 있는데 하지 말자. 멀티스레딩을 위한 것이기도 하고, 큐가 매우 느리다. 링크: https:..
skeo131.tistory.com
import collections
def solution(cacheSize, cities):
cache = collections.deque(maxlen=cacheSize)
time = 0
for i in cities:
s = i.lower()
if s in cache:
cache.remove(s)
cache.append(s)
time += 1
else:
cache.append(s)
time += 5
return time
📌리뷰
- deque의 maxlen으로 리스트 크기 조절 가능
- LRU 알고리즘
728x90
'Coding Test > 프로그래머스(Python)' 카테고리의 다른 글
[프로그래머스] Level 2_괄호 회전하기(월간 코드 챌린지 시즌2) (0) | 2022.10.14 |
---|---|
[프로그래머스] Level 2_행렬의 곱셈(연습문제) (0) | 2022.10.13 |
[프로그래머스] Level 2_점프와 순간 이동(Summer/Winter Coding(~2018)) (0) | 2022.10.13 |
[프로그래머스] Level 2_숫자의 표현(연습문제) (0) | 2022.10.12 |
[프로그래머스] Level 2_멀리뛰기(연습문제) (1) | 2022.10.08 |
Comments