Leetcode Problem 1396. Design Underground System

1396. Design Underground System

Leetcode Solutions

Using HashMaps to Track Check-ins and Calculate Averages

  1. Initialize two HashMaps: checkInData to store check-in information and journeyData to store journey times and counts.
  2. Implement checkIn method to store the customer's ID, station name, and check-in time in checkInData.
  3. Implement checkOut method to retrieve the check-in data, calculate the journey time, and update journeyData with the new total time and increment the journey count.
  4. Implement getAverageTime method to retrieve the total time and count from journeyData for the given start and end stations, and return the average time by dividing the total time by the count.
UML Thumbnail

Using Nested HashMaps for Journey Tracking

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...