We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0a4ae0e commit 55c6624Copy full SHA for 55c6624
C++/minimum-time-difference.cpp
@@ -0,0 +1,19 @@
1
+// Time: O(nlogn)
2
+// Space: O(n)
3
+
4
+class Solution {
5
+public:
6
+ int findMinDifference(vector<string>& timePoints) {
7
+ static const int N = 60 * 24;
8
+ vector<int> minutes;
9
+ for (const auto& t : timePoints) {
10
+ minutes.emplace_back(stoi(t.substr(0, 2)) * 60 + stoi(t.substr(3)));
11
+ }
12
+ sort(minutes.begin(), minutes.end());
13
+ int result = numeric_limits<int>::max();
14
+ for (int i = 0; i < timePoints.size(); ++i) {
15
+ result = min(result, (N + minutes[(i + 1) % timePoints.size()] - minutes[i]) % N);
16
17
+ return result;
18
19
+};
0 commit comments