Leetcode Problem 2749. Minimum Operations to Make the Integer Zero
2749. Minimum Operations to Make the Integer Zero
Leetcode Solutions
Iterative Bit Count Approach
Initialize ans to 0.
Start a loop that continues until the bit count of num1 is greater than ans.
a. Increment ans by 1.
b. Subtract num2 from num1.
c. If num1 is less than ans and num2 is positive, return -1.
d. If the bit count of num1 is less than or equal to ans, return ans.