class Solution {
public:
int timeDifference(pair<int, int> before, pair<int, int> after){
unsigned diff = 0;
if (after.first == before.first) diff = after.second - before.second;
else {
diff += after.second - before.second + 60;
before.first++;
diff += (after.first - before.first) * 60;
}
return diff;
}
int findMinDifference(vector<string>& timePoints) {
int currDifference{0}, minDifference{1441};
pair<int, int> before, after;
sort(timePoints.begin(), timePoints.end());
before = make_pair(stoi(timePoints[timePoints.size()-1].substr(0, 2)), stoi(timePoints[timePoints.size()-1].substr(3, 2)));
after = make_pair(stoi(timePoints[0].substr(0, 2)) + 24, stoi(timePoints[0].substr(3, 2)));
currDifference = timeDifference(before, after);
minDifference = min(currDifference, minDifference);
for (int i = 1; i < timePoints.size(); i++){
before = make_pair(stoi(timePoints[i-1].substr(0, 2)), stoi(timePoints[i-1].substr(3, 2)));
after = make_pair(stoi(timePoints[i].substr(0, 2)), stoi(timePoints[i].substr(3, 2)));
currDifference = timeDifference(before, after);
minDifference = min(currDifference, minDifference);
}
return minDifference;
}
};