Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26ef690

Browse files
authored
Create 1396-design-underground-system.py
1 parentbba9e31 commit26ef690

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
classUndergroundSystem:
2+
def__init__(self):
3+
# save as {customer_id: (stationName, t)}
4+
self.customer= {}
5+
6+
# save time travel for route = (src,dst) each time a customer checkout
7+
# save as {(src, dst): (total_time, count)}
8+
self.time= {}
9+
10+
defcheckIn(self,id:int,stationName:str,t:int)->None:
11+
self.customer[id]= (stationName,t)
12+
13+
defcheckOut(self,id:int,stationName:str,t:int)->None:
14+
start,time=self.customer[id]
15+
route= (start,stationName)
16+
17+
# save new entity to time table
18+
ifroutenotinself.time:self.time[route]= [0,0]
19+
self.time[route][0]+=t-time
20+
self.time[route][1]+=1
21+
22+
23+
defgetAverageTime(self,startStation:str,endStation:str)->float:
24+
total,count=self.time[(startStation,endStation)]
25+
returntotal/count

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp