C++ solution, 12ms


  • 0
    Z
    #define CHAR2INT(ch) (ch - '0')
    
    class Solution {
    public:
        int findMinDifference(vector<string>& time_points) {
            int clock[2880] = {};    // 2 * 24 * 60
            int curr = 0, tend = 1440;
            for(string time_point : time_points) {
                curr = (CHAR2INT(time_point[0]) * 10 + CHAR2INT(time_point[1])) * 60 + 
                        CHAR2INT(time_point[3]) * 10 + CHAR2INT(time_point[4]);  //Real time.
                tend = curr + 1440;   //time + 24 * 60, time for loop.
                ++clock[curr];
                ++clock[tend]; 
            }
            int last = curr, min_ret = INT_MAX;
            for(++curr; curr <= tend; ++curr) {
                if(clock[curr] > 1) {
                    return 0;
                } else if(clock[curr]) {
                    min_ret = min(min_ret, curr - last);
                    last = curr;
                }
            }
            return min_ret;
        }
    };
    

Log in to reply
 

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