Skip to content

Commit 0a0f5e6

Browse files
authored
Create count-operations-to-obtain-zero.cpp
1 parent 81c6f19 commit 0a0f5e6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Time: O(log(min(m, n)))
2+
// Space: O(1)
3+
4+
// gcd-like solution
5+
class Solution {
6+
public:
7+
int countOperations(int num1, int num2) {
8+
int result = 0;
9+
while (num2) {
10+
result += num1 / num2;
11+
tie(num1, num2) = make_pair(num2, num1 % num2);
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)