1611. Minimum One Bit Operations to Make Integers Zero
https://leetcode.com/problems/minimum-one-bit-operations-to-make-integers-zero
Description
Given an integer n, you must transform it into 0 using the following operations any number of times:
Change the rightmost (
0th) bit in the binary representation ofn.Change the
ithbit in the binary representation ofnif the(i-1)thbit is set to1and the(i-2)ththrough0thbits are set to0.
Return the minimum number of operations to transform n into 0.
Example 1:
**Input:** n = 0
**Output:** 0Example 2:
**Input:** n = 3
**Output:** 2
**Explanation:** The binary representation of 3 is "11".
"11" -> "01" with the 2nd operation since the 0th bit is 1.
"01" -> "00" with the 1st operation.Example 3:
**Input:** n = 6
**Output:** 4
**Explanation:** The binary representation of 6 is "110".
"110" -> "010" with the 2nd operation since the 1st bit is 1 and 0th through 0th bits are 0.
"010" -> "011" with the 1st operation.
"011" -> "001" with the 2nd operation since the 0th bit is 1.
"001" -> "000" with the 1st operation.Example 4:
**Input:** n = 9
**Output:** 14Example 5:
**Input:** n = 333
**Output:** 393Constraints:
0 <= n <= 109
ac
Previous1610. Maximum Number of Visible PointsNext1612. Check If Two Expression Trees are Equivalent
Last updated
Was this helpful?