Skip to content

Commit 66cfb13

Browse files
solves #2169: Count Operations to Obtain Zero in java
1 parent 8604837 commit 66cfb13

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@
712712
| 2154 | [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two) | [![Java](assets/java.png)](src/KeepMultiplyingFoundValuesByTwo.java) | |
713713
| 2160 | [Minimum Sum of Four Digit Number After Splitting Digits](https://leetcode.com/problems/minimum-sum-of-four-digit-number-after-splitting-digits) | [![Java](assets/java.png)](src/MinimumSumOfFourDigitNumberAfterSplittingDigits.java) | |
714714
| 2164 | [Sort Even and Odd Indices Independently](https://leetcode.com/problems/sort-even-and-odd-indices-independently) | [![Java](assets/java.png)](src/SortEvenAndOddIndicesIndependently.java) | |
715-
| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | | |
715+
| 2169 | [Count Operations to Obtain Zero](https://leetcode.com/problems/count-operations-to-obtain-zero) | [![Java](assets/java.png)](src/CountOperationsToObtainZero.java) | |
716716
| 2176 | [Count Equal and Divisible Pairs in an Array](https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array) | | |
717717
| 2180 | [Count Integers With Even Digit Sum](https://leetcode.com/problems/count-integers-with-even-digit-sum) | [![Java](assets/java.png)](src/CountIntegersWithEvenDigitSum.java) | |
718718
| 2185 | [Counting Words With a Given Prefix](https://leetcode.com/problems/counting-words-with-a-given-prefix) | | |

Diff for: src/CountOperationsToObtainZero.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://leetcode.com/problems/count-operations-to-obtain-zero
2+
// T: O(max(a, b))
3+
// S: O(1)
4+
5+
public class CountOperationsToObtainZero {
6+
public int countOperations(int num1, int num2) {
7+
int operations = 0;
8+
while (num1 != 0 && num2 != 0) {
9+
operations++;
10+
if (num1 >= num2) {
11+
num1 -= num2;
12+
} else num2 -= num1;
13+
}
14+
return operations;
15+
}
16+
}

0 commit comments

Comments
 (0)