c++ solution extremely easy to understand


  • 0
    Q
    class Solution {
    public:
        int findMinDifference(vector<string>& timePoints) {
            vector<int> tmp;
            for(auto it: timePoints){
                int i = (it[4]-'0') + (it[3]-'0')*10 + (it[1]-'0') * 60 + (it[0]-'0') * 600;
                tmp.push_back(i);
            }
            sort(tmp.begin(),tmp.end());
            
            int res = INT_MAX;
            for(int i=0;i<tmp.size()-1;i++)
                res = min(res,min(tmp[i+1]-tmp[i], 1440-tmp[i+1]+tmp[i]));
            res = min(res, min(tmp[tmp.size()-1] - tmp[0], 1440-tmp[tmp.size()-1]+tmp[0]));
            return res;
        }
    };
    

Log in to reply
 

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