Skip to content
LC-2224 Easy LeetCode

2224. Minimum Number of Operations to Convert Time

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 65% Topics: String, Greedy
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(1)
# Space: O(1)

# greedy
class Solution(object):
    def convertTime(self, current, correct):
        """
        :type current: str
        :type correct: str
        :rtype: int
        """
        OPS = (60, 15, 5, 1)
        diff = (int(correct[:2])*60+int(correct[3:]))-(int(current[:2])*60+int(current[3:]))
        result = 0
        for x in OPS:
            q, diff = divmod(diff, x)
            result += q
        return result

Solution from kamyu104/LeetCode-Solutions · MIT