|
1 |
| - |
| 1 | +/** |
| 2 | + * https://leetcode-cn.com/problems/design-underground-system/submissions/ |
| 3 | + * |
| 4 | + * Medium |
| 5 | + * |
| 6 | + * 5370. 设计地铁系统 |
| 7 | + * |
| 8 | + * 300ms 100.00% |
| 9 | + * 59.3mb 100.00% |
| 10 | + */ |
2 | 11 | var UndergroundSystem = function() {
|
3 |
| - this.inMap = new Map(); |
| 12 | + this.record = new Map(); |
4 | 13 | this.resultMap = new Map();
|
5 | 14 | };
|
6 | 15 |
|
7 |
| -/** |
8 |
| - * @param {number} id |
9 |
| - * @param {string} stationName |
10 |
| - * @param {number} t |
11 |
| - * @return {void} |
12 |
| - */ |
13 | 16 | UndergroundSystem.prototype.checkIn = function(id, stationName, t) {
|
14 |
| - this.inMap.set(id, [stationName, t]); |
| 17 | + this.record.set(id, [stationName, t]); |
15 | 18 | };
|
16 | 19 |
|
17 |
| -/** |
18 |
| - * @param {number} id |
19 |
| - * @param {string} stationName |
20 |
| - * @param {number} t |
21 |
| - * @return {void} |
22 |
| - */ |
23 | 20 | UndergroundSystem.prototype.checkOut = function(id, stationName, t) {
|
24 |
| - const [startStation, startT] = this.inMap.get(id); |
| 21 | + const [startStation, startT] = this.record.get(id); |
25 | 22 | const time = t - startT;
|
26 | 23 | if (!this.resultMap.has(`${startStation}-${stationName}`)) {
|
27 | 24 | this.resultMap.set(`${startStation}-${stationName}`, []);
|
28 | 25 | }
|
29 | 26 | this.resultMap.get(`${startStation}-${stationName}`).push(time);
|
30 |
| - this.inMap.delete(id); |
| 27 | + this.record.delete(id); |
31 | 28 | };
|
32 |
| - |
33 |
| -/** |
34 |
| - * @param {string} startStation |
35 |
| - * @param {string} endStation |
36 |
| - * @return {number} |
37 |
| - */ |
38 | 29 | UndergroundSystem.prototype.getAverageTime = function(startStation, endStation) {
|
39 | 30 | const list = this.resultMap.get(`${startStation}-${endStation}`);
|
40 | 31 | const max = list.length;
|
|
0 commit comments