Class Solution
-
- All Implemented Interfaces:
public final class Solution2749 - Minimum Operations to Make the Integer Zero.
Medium
You are given two integers
num1andnum2.In one operation, you can choose integer
iin the range[0, 60]and subtract <code>2<sup>i</sup> + num2</code> fromnum1.Return the integer denoting the minimum number of operations needed to make
num1equal to0.If it is impossible to make
num1equal to0, return-1.Example 1:
Input: num1 = 3, num2 = -2
Output: 3
Explanation: We can make 3 equal to 0 with the following operations:
We choose i = 2 and substract 2<sup>2</sup> + (-2) from 3, 3 - (4 + (-2)) = 1.
We choose i = 2 and substract 2<sup>2</sup> + (-2) from 1, 1 - (4 + (-2)) = -1.
We choose i = 0 and substract 2<sup>0</sup> + (-2) from -1, (-1) - (1 + (-2)) = 0.
It can be proven, that 3 is the minimum number of operations that we need to perform.
Example 2:
Input: num1 = 5, num2 = 7
Output: -1
Explanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
Constraints:
<code>1 <= num1 <= 10<sup>9</sup></code>
<code>-10<sup>9</sup><= num2 <= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegermakeTheIntegerZero(Integer num1, Integer num2)-
-
Method Detail
-
makeTheIntegerZero
final Integer makeTheIntegerZero(Integer num1, Integer num2)
-
-
-
-