Skip to content

Commit d58317c

Browse files
authored
Create count-operations-to-obtain-zero.py
1 parent 0a0f5e6 commit d58317c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Time: O(log(min(m, n)))
2+
# Space: O(1)
3+
4+
# gcd-like solution
5+
class Solution(object):
6+
def countOperations(self, num1, num2):
7+
"""
8+
:type num1: int
9+
:type num2: int
10+
:rtype: int
11+
"""
12+
result = 0
13+
while num2:
14+
result += num1//num2
15+
num1, num2 = num2, num1%num2
16+
return result

0 commit comments

Comments
 (0)