1
+ class UndergroundSystem :
2
+
3
+ def __init__ (self ):
4
+ self .enterstation = {}
5
+ self .leavestation = {}
6
+
7
+ def checkIn (self , id : int , stationName : str , t : int ) -> None :
8
+ if stationName not in self .enterstation :
9
+ self .enterstation [stationName ] = [[id , t ]]
10
+ else :
11
+ self .enterstation [stationName ].append ([id , t ])
12
+
13
+ def checkOut (self , id : int , stationName : str , t : int ) -> None :
14
+ if stationName not in self .leavestation :
15
+ self .leavestation [stationName ] = [[id , t ]]
16
+ else :
17
+ self .leavestation [stationName ].append ([id , t ])
18
+
19
+ def getAverageTime (self , startStation : str , endStation : str ) -> float :
20
+ res = []
21
+ start = self .enterstation [startStation ]
22
+ end = self .leavestation [endStation ]
23
+ for i in start :
24
+ for j in end :
25
+ # id相同
26
+ if i [0 ] == j [0 ]:
27
+ res .append (abs (j [1 ] - i [1 ]))
28
+ return float (sum (res ) / len (res ))
29
+
30
+
31
+ # Your UndergroundSystem object will be instantiated and called as such:
32
+ # obj = UndergroundSystem()
33
+ # obj.checkIn(id,stationName,t)
34
+ # obj.checkOut(id,stationName,t)
35
+ # param_3 = obj.getAverageTime(startStation,endStation)
0 commit comments