leetcode-第十九周

来源:互联网 发布:mac没有 hosts文件 编辑:程序博客网 时间:2024/06/03 19:16

539. Minimum Time Difference

class Solution {private:    int toInt(const string &s) {        char c; int h, m;        stringstream ss(s);        ss >> h >> c >> m;        return h * 60 + m;    }public:    int findMinDifference(vector<string>& timePoints) {        vector<int> vec;        int ret = INT_MAX;        for (auto &t: timePoints) vec.push_back(toInt(t));        sort(vec.begin(), vec.end());        //vec.push_back(vec.front());        for (auto v: vec) cout << v << " "; cout << endl;        for (int i = 1; i < vec.size(); i++) {            int val = vec[i] - vec[i - 1];            ret = min(ret, val);        }        ret = min(ret, vec.back() - vec.front());        ret = min(ret, (1440 + vec.front() - vec.back()) % 1440);        return ret;    }};