Skip to content

Commit

Permalink
2169
Browse files Browse the repository at this point in the history
  • Loading branch information
lzl124631x committed Feb 17, 2022
1 parent a53db01 commit 5347f46
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion leetcode/2169. Count Operations to Obtain Zero/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ So the total number of operations required is 1.
```cpp
// OJ: https://leetcode.com/problems/count-operations-to-obtain-zero/
// Author: github.com/lzl124631x
// Time: O(num1 + num2)
// Time: O(max(num1, num2))
// Space: O(1)
class Solution {
public:
Expand All @@ -64,6 +64,26 @@ public:
};
```
## Solution 2.
```cpp
// OJ: https://leetcode.com/problems/count-operations-to-obtain-zero/
// Author: github.com/lzl124631x
// Time: O(max(num1, num2))
// Space: O(1)
class Solution {
public:
int countOperations(int num1, int num2) {
int ans = 0;
while (num1 && num2) {
if (num1 >= num2) ans += num1 / num2, num1 %= num2;
else ans += num2 / num1, num2 %= num1;
}
return ans;
}
};
```

## Discuss

https://leetcode.com/problems/count-operations-to-obtain-zero/discuss/1766767

0 comments on commit 5347f46

Please sign in to comment.