10 lines C++


  • 0
    S
    class Solution {
    public:
        int findMinDifference(vector<string>& timePoints) {
            vector<int> timeint(timePoints.size());
            for (int i = 0; i < timePoints.size(); i++)
                timeint[i] = stoi(timePoints[i].substr(0,2))*60 + stoi(timePoints[i].substr(3,2));
            sort(timeint.begin(), timeint.end());
            timeint.push_back(timeint[0] + 24*60);
            int mintime = 24*60;
            for (int i = 0; i < timePoints.size(); i++)
                mintime = min(mintime, timeint[i+1]-timeint[i]);
            return mintime;
        }
    };
    

Log in to reply
 

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