2749. Minimum Operations to Make the Integer Zero Medium
1/**
2 * [2749] Minimum Operations to Make the Integer Zero
3 *
4 * You are given two integers num1 and num2.
5 * In one operation, you can choose integer i in the range [0, 60] and subtract 2^i + num2 from num1.
6 * Return the integer denoting the minimum number of operations needed to make num1 equal to 0.
7 * If it is impossible to make num1 equal to 0, return -1.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: num1 = 3, num2 = -2
12 * Output: 3
13 * Explanation: We can make 3 equal to 0 with the following operations:
14 * - We choose i = 2 and subtract 2^2 + (-2) from 3, 3 - (4 + (-2)) = 1.
15 * - We choose i = 2 and subtract 2^2 + (-2) from 1, 1 - (4 + (-2)) = -1.
16 * - We choose i = 0 and subtract 2^0 + (-2) from -1, (-1) - (1 + (-2)) = 0.
17 * It can be proven, that 3 is the minimum number of operations that we need to perform.
18 *
19 * <strong class="example">Example 2:
20 *
21 * Input: num1 = 5, num2 = 7
22 * Output: -1
23 * Explanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= num1 <= 10^9
29 * <font face="monospace">-10^9 <= num2 <= 10^9</font>
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-operations-to-make-the-integer-zero/
35// discuss: https://leetcode.com/problems/minimum-operations-to-make-the-integer-zero/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn make_the_integer_zero(num1: i32, num2: i32) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2749() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.