일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 스탭퍼
- 개발자
- 30분
- 미드시청
- 읽기
- 영어원서읽기
- leetcode
- FIT XR
- 잡생각
- Writing
- 리얼 클래스
- realclass
- 영어공부
- English
- 프로젝트
- 운동
- Problem Solving
- 만화도
- 3줄정리
- 뭐든
- 링피트
- 화상영어
- 월간
- 쓰릴오브파이트
- 매일
- 파비최
- 사이드
- Daily Challenge
- 10분
- 괜찮음
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.05.31 Today's Challenge 본문
https://leetcode.com/problems/design-underground-system/
Design Underground System - LeetCode
Can you solve this real interview question? Design Underground System - An underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one s
leetcode.com
소스가 꽤 김
class UndergroundSystem:
def __init__(self):
self.tt = {}
self.ci = {}
def checkIn(self, id: int, stationName: str, t: int) -> None:
self.ci[id] = (stationName, t)
def checkOut(self, id: int, stationName: str, t: int) -> None:
ss, cit = self.ci.pop(id)
travel = (ss, stationName)
travel_time = t - cit
if travel in self.tt:
total_time, count = self.tt[travel]
self.tt[travel] = (total_time + travel_time, count+1)
else:
self.tt[travel] = (travel_time, 1)
def getAverageTime(self, startStation: str, endStation: str) -> float:
travel = (startStation, endStation)
total_time, count = self.tt[travel]
return total_time / count
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.06.02 Today's Challenge (0) | 2023.06.02 |
---|---|
2023.06.01 Today's Challenge (0) | 2023.06.01 |
2023.05.30 Today's Challenge (0) | 2023.05.30 |
2023.05.29 Today's Challenge (0) | 2023.05.29 |
2023.05.28 Today's Challenge (0) | 2023.05.28 |
Comments