leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1396.cpp (673B)
0 class UndergroundSystem {
1 unordered_map<int, pair<string, int>> check_in;
2 unordered_map<string, pair<int, int>> average;
4 public:
5 UndergroundSystem() {}
7 void checkIn(int id, const string &stationName, int t) { check_in[id] = {stationName, t}; }
9 void checkOut(int id, const string &stationName, int t) {
10 auto &[name, time] = check_in[id];
11 auto &p = average[name + "-" + stationName];
12 p.second += t - time;
13 p.first++;
14 }
16 double getAverageTime(const string &startStation, const string &endStation) {
17 auto &p = average[startStation + "-" + endStation];
18 return (double)p.second / p.first;
19 }
20 };