Class Solution
-
- All Implemented Interfaces:
public final class Solution2998 - Minimum Number of Operations to Make X and Y Equal.
Medium
You are given two positive integers
xandy.In one operation, you can do one of the four following operations:
Divide
xby11ifxis a multiple of11.Divide
xby5ifxis a multiple of5.Decrement
xby1.Increment
xby1.
Return the minimum number of operations required to make
xandyequal.Example 1:
Input: x = 26, y = 1
Output: 3
Explanation: We can make 26 equal to 1 by applying the following operations:
Decrement x by 1
Divide x by 5
Divide x by 5
It can be shown that 3 is the minimum number of operations required to make 26 equal to 1.
Example 2:
Input: x = 54, y = 2
Output: 4
Explanation: We can make 54 equal to 2 by applying the following operations:
Increment x by 1
Divide x by 11
Divide x by 5
Increment x by 1
It can be shown that 4 is the minimum number of operations required to make 54 equal to 2.
Example 3:
Input: x = 25, y = 30
Output: 5
Explanation: We can make 25 equal to 30 by applying the following operations:
Increment x by 1
Increment x by 1
Increment x by 1
Increment x by 1
Increment x by 1
It can be shown that 5 is the minimum number of operations required to make 25 equal to 30.
Constraints:
<code>1 <= x, y <= 10<sup>4</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminimumOperationsToMakeEqual(Integer x, Integer y)-
-
Method Detail
-
minimumOperationsToMakeEqual
final Integer minimumOperationsToMakeEqual(Integer x, Integer y)
-
-
-
-