less than 1 minute read

<-E 2224> Minimum Number of Operations to Convert Time

class Solution {
    private:
    constexpr static int MINUTES_IN_DAY = 24 * 60;

    int getMinutes(const string& t) {
        int hour = stoi(t.substr(0, 2));
        int minute = stoi(t.substr(3));
        return hour * 60 + minute;
    }
public:
    int convertTime(string current, string correct) {
        int from = getMinutes(current);
        int to = getMinutes(correct);
        int diff = (to - from + MINUTES_IN_DAY) % MINUTES_IN_DAY;
        vector<int> moves {60, 15, 5, 1};
        int ret = 0;
        for (auto move: moves) {
            ret += diff / move;
            diff %= move;
        }
        return ret;
    }
};