easy C++ solution


  • 0
    A
    class Solution {
    public:
        int findMinDifference(vector<string>& timePoints) {
            vector<int> nums;
            for (string &tp : timePoints) {
                int h = stoi(tp.substr(0, 2)), m = stoi(tp.substr(3, 2));
                nums.push_back(h * 60 + m);
            }
            sort(nums.begin(), nums.end());
            int ans = INT_MAX;
            if (nums.size() > 1) {
                ans = min(ans, nums.front() + 1440 - nums.back());
                for (int i = 1; i < nums.size(); ++i)
                    ans = min(ans, nums[i] - nums[i - 1]);
            }
            return ans;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.