Try   HackMD

539. Minimum Time Difference


My Solution

The Key Idea for Solving This Coding Question

C++ Code

class Solution { public: int findMinDifference(vector<string> &timePoints) { vector<int> timestamps; for (int i = 0; i < timePoints.size(); ++i) { timestamps.push_back(toTimestamp(timePoints[i])); } sort(timestamps.begin(), timestamps.end()); // 24 * 60 = 1440 int minDiff = 1440 - timestamps.back() + timestamps[0]; for (int i = 1; i < timestamps.size(); ++i) { minDiff = min(minDiff, timestamps[i] - timestamps[i - 1]); } return minDiff; } private: int toTimestamp(string &t) { int hh = (t[0] - '0') * 10 + (t[1] - '0'); int mm = (t[3] - '0') * 10 + (t[4] - '0'); return hh * 60 + mm; } };

Time Complexity

Space Complexity

Miscellane