--- tags: leetcode --- # [539. Minimum Time Difference](https://leetcode.com/problems/minimum-time-difference/) --- # My Solution ## The Key Idea for Solving This Coding Question ## C++ Code ```cpp= 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 <!-- # Test Cases ``` ["23:59","00:00"] ``` ``` ["00:00","23:59","00:00"] ``` * Wrong Answer ``` ["05:31","22:08","00:35"] ``` -->
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up