c++ bitset


  • 0
    T
    class Solution {
    public:
        int findMinDifference(vector<string>& timePoints) {
            bitset<60*24> dict;
            for (string &s:timePoints) {
                int p = s.find(":");
                int h = atoi(s.substr(0, p).c_str()), m = atoi(s.substr(p+1).c_str());
                int indx = h*60 + m;
                if (dict[indx]) return 0;
                dict[indx] = 1;
            }
            int min_diff = INT_MAX, first = -1, last = -1;
            for (int i = -1, j = 0, sz = 24*60; j < sz; ++j) {
                if (dict[j]) {
                    if (i < 0) {i = j; first = j; continue;}
                    min_diff = min(min_diff, j-i);
                    i = last = j;
                }
            }
            return min_diff = min(min_diff, 24*60-last+first);
        }
    };
    

Log in to reply
 

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