일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 만화도
- 파비최
- 프로젝트
- 사이드
- 개발자
- FIT XR
- 뭐든
- Daily Challenge
- 리얼 클래스
- 운동
- 10분
- realclass
- Problem Solving
- 영어원서읽기
- 쓰릴오브파이트
- 스탭퍼
- 월간
- Writing
- 화상영어
- 읽기
- 링피트
- 매일
- English
- 30분
- 미드시청
- 3줄정리
- leetcode
- 영어공부
- 잡생각
- 괜찮음
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/time-based-key-value-store/
Time Based Key-Value Store - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
주어진 조건에 따라 클래스 만드는거라 약간 모델링 하는거랑 비슷.
class TimeMap:
def __init__(self):
self.m = {}
def set(self, key: str, value: str, timestamp: int) -> None:
if not key in self.m:
self.m[key] = {}
self.m[key][timestamp] = value
def get(self, key: str, timestamp: int) -> str:
if not key in self.m:
return ''
for curr_time in reversed(range(1, timestamp+1)):
if curr_time in self.m[key]:
return self.m[key][curr_time]
return ''
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.10.08 |
---|---|
Today's Challenge (0) | 2022.10.07 |
Today's Challenge (0) | 2022.10.05 |
Today's Challenge (0) | 2022.10.04 |
Today's Challenge (1) | 2022.10.03 |
Comments