classUndergroundSystem{ val startStations = HashMap<Int, String>() val startT = HashMap<Int, Int>() val time = HashMap<String, Int>() val count = HashMap<String, Int>()
fun checkIn(id: Int, stationName: String, t: Int){ startStations[id] = stationName startT[id] = t }
fun checkOut(id: Int, stationName: String, t: Int){ val s = startStations.getOrDefault(id, "") + '#' + stationName time[s] = time.getOrDefault(s, 0) + t - startT.getOrDefault(id, 0) count[s] = count.getOrDefault(s, 0) + 1 }
fun getAverageTime(startStation: String, endStation: String): Double { val s = "$startStation#$endStation" return time[s]!! * 1.0 / count[s]!! } }