Straightforward C++ solution


  • 0
    D
    int findMinDifference(vector<string>& timePoints) {
        int size = timePoints.size();
        vector<int> vi;
        for (auto timePoint : timePoints)
        {
            int time = stoi(timePoint.substr(0, 2)) * 60 + 
                       stoi(timePoint.substr(3));
            vi.push_back(time);
        }
        sort(vi.begin(), vi.end());
        int minDiff = vi[0] + 24*60 - vi[size-1];
        for(int i = 1; i < size; i++)
        {
            int diff = vi[i] - vi[i-1];
            if(minDiff > diff) minDiff = diff;
        }
        return minDiff;
    }

  • 0
    D

    The only thing we need to be careful is the difference between first and last one.


Log in to reply
 

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