|
| 1 | +classUndergroundSystem() { |
| 2 | + |
| 3 | +val checkIn=HashMap<Int,Pair<String,Int>>()// id -> (startStation to time) |
| 4 | +val averageTime=HashMap<String,Pair<Double,Int>>()// startion -> (TotalTime to countOfTrips) |
| 5 | + |
| 6 | +funcheckIn(id:Int,start:String,startTime:Int) { |
| 7 | + checkIn[id]= start to startTime |
| 8 | + } |
| 9 | + |
| 10 | +funcheckOut(id:Int,end:String,endTime:Int) { |
| 11 | +val (start, startTime)= checkIn[id]!! |
| 12 | +val fromTo="$start:$end" |
| 13 | +val (total, count)= averageTime.getOrDefault(fromTo,0.0 to0) |
| 14 | + averageTime[fromTo]= (total+ endTime- startTime) to (count+1) |
| 15 | + } |
| 16 | + |
| 17 | +fungetAverageTime(start:String,end:String):Double { |
| 18 | +val (total, count)= averageTime.getOrDefault("$start:$end",0.0 to0) |
| 19 | +return total/ count |
| 20 | + } |
| 21 | + |
| 22 | +} |