Skip to content
LC-2169 Easy LeetCode

2169. Count Operations to Obtain Zero

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 75% Topics: Math, Simulation
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(log(min(m, n)))
# Space: O(1)

# gcd-like solution
class Solution(object):
    def countOperations(self, num1, num2):
        """
        :type num1: int
        :type num2: int
        :rtype: int
        """
        result = 0
        while num2:
            result += num1//num2
            num1, num2 = num2, num1%num2
        return result

Solution from kamyu104/LeetCode-Solutions · MIT