1396. Design Underground System
https://leetcode.com/problems/design-underground-system
Description
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 station to another.
Implement the UndergroundSystem
class:
void checkIn(int id, string stationName, int t)
A customer with a card ID equal to
id
, checks in at the stationstationName
at timet
.A customer can only be checked into one place at a time.
void checkOut(int id, string stationName, int t)
A customer with a card ID equal to
id
, checks out from the stationstationName
at timet
.
double getAverageTime(string startStation, string endStation)
Returns the average time it takes to travel from
startStation
toendStation
.The average time is computed from all the previous traveling times from
startStation
toendStation
that happened directly, meaning a check in atstartStation
followed by a check out fromendStation
.The time it takes to travel from
startStation
toendStation
may be different from the time it takes to travel fromendStation
tostartStation
.There will be at least one customer that has traveled from
startStation
toendStation
beforegetAverageTime
is called.
You may assume all calls to the checkIn
and checkOut
methods are consistent. If a customer checks in at time t1
then checks out at time t2
, then t1 < t2
. All events happen in chronological order.
Example 1:
Example 2:
Constraints:
1 <= id, t <= 106
1 <= stationName.length, startStation.length, endStation.length <= 10
All strings consist of uppercase and lowercase English letters and digits.
There will be at most
2 * 104
calls in total tocheckIn
,checkOut
, andgetAverageTime
.Answers within
10-5
of the actual value will be accepted.
ac
Last updated