Class Solution
java.lang.Object
g2101_2200.s2169_count_operations_to_obtain_zero.Solution
2169 - Count Operations to Obtain Zero.<p>Easy</p>
<p>You are given two <strong>non-negative</strong> integers <code>num1</code> and <code>num2</code>.</p>
<p>In one <strong>operation</strong> , if <code>num1 >= num2</code>, you must subtract <code>num2</code> from <code>num1</code>, otherwise subtract <code>num1</code> from <code>num2</code>.</p>
<ul>
<li>For example, if <code>num1 = 5</code> and <code>num2 = 4</code>, subtract <code>num2</code> from <code>num1</code>, thus obtaining <code>num1 = 1</code> and <code>num2 = 4</code>. However, if <code>num1 = 4</code> and <code>num2 = 5</code>, after one operation, <code>num1 = 4</code> and <code>num2 = 1</code>.</li>
</ul>
<p>Return <em>the <strong>number of operations</strong> required to make either</em> <code>num1 = 0</code> <em>or</em> <code>num2 = 0</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> num1 = 2, num2 = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>
<p>Operation 1: num1 = 2, num2 = 3. Since num1 < num2, we subtract num1 from num2 and get num1 = 2, num2 = 3 - 2 = 1.</p>
</li>
<li>
<p>Operation 2: num1 = 2, num2 = 1. Since num1 > num2, we subtract num2 from num1.</p>
</li>
<li>
<p>Operation 3: num1 = 1, num2 = 1. Since num1 == num2, we subtract num2 from num1.</p>
</li>
</ul>
<p>Now num1 = 0 and num2 = 1. Since num1 == 0, we do not need to perform any further operations.</p>
<p>So the total number of operations required is 3.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> num1 = 10, num2 = 10</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong></p>
<ul>
<li>Operation 1: num1 = 10, num2 = 10. Since num1 == num2, we subtract num2 from num1 and get num1 = 10 - 10 = 0.</li>
</ul>
<p>Now num1 = 0 and num2 = 10. Since num1 == 0, we are done.</p>
<p>So the total number of operations required is 1.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>0 <= num1, num2 <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countOperations
public int countOperations(int num1, int num2)
-