일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 파비최
- 괜찮음
- 쓰릴오브파이트
- Daily Challenge
- 잡생각
- 만화도
- 3줄정리
- 스탭퍼
- 뭐든
- 매일
- 읽기
- 화상영어
- FIT XR
- 미드시청
- 운동
- 30분
- leetcode
- 10분
- 링피트
- 월간
- realclass
- Problem Solving
- 프로젝트
- English
- 영어원서읽기
- 리얼 클래스
- 사이드
- 개발자
- Writing
- 영어공부
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.19 Today's Challenge 본문
https://leetcode.com/problems/design-a-food-rating-system/?envType=daily-question&envId=2023-12-17
HashMap을 활용해서 푸는 문제
class Food:
def __init__(self, food_rating, food_name):
self.food_rating = food_rating
self.food_name = food_name
def __lt__(self, other):
if self.food_rating == other.food_rating:
return self.food_name < other.food_name
return self.food_rating > other.food_rating
class FoodRatings:
def __init__(self, foods: List[str], cuisines: List[str], ratings: List[int]):
self.food_rating_map = {}
self.food_cuisine_map = {}
self.cuisine_food_map = defaultdict(list)
for i in range(len(foods)):
self.food_rating_map[foods[i]] = ratings[i]
self.food_cuisine_map[foods[i]] = cuisines[i]
heapq.heappush(self.cuisine_food_map[cuisines[i]], Food(ratings[i], foods[i]))
def changeRating(self, food: str, newRating: int) -> None:
self.food_rating_map[food] = newRating
cuisineName = self.food_cuisine_map[food]
heapq.heappush(self.cuisine_food_map[cuisineName], Food(newRating, food))
def highestRated(self, cuisine: str) -> str:
highest_rated = self.cuisine_food_map[cuisine][0]
while self.food_rating_map[highest_rated.food_name] != highest_rated.food_rating:
heapq.heappop(self.cuisine_food_map[cuisine])
highest_rated = self.cuisine_food_map[cuisine][0]
return highest_rated.food_name
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.21 Today's Challenge (0) | 2023.12.21 |
---|---|
2023.12.20 Today's Challenge (1) | 2023.12.20 |
2023.12.18 Today's Challenge (0) | 2023.12.18 |
2023.12.17 Today's Challenge (0) | 2023.12.17 |
2023.12.16 Today's Challenge (1) | 2023.12.16 |
Comments