Minimum One Bit Operations to Make Integers Zero LeetCode solution in Python
1class Solution:2def minimumOneBitOperations(self, n: int) -> int:3if n <= 1:4return n56def leftmostbit(x):7x |= x >> 18x |= x >> 29x |= x >> 410x |= x >> 811x |= x >> 1612x += 113x >>= 114return x1516x = leftmostbit(n)17return ((x << 1) - 1) - self.minimumOneBitOperations(n - x)