LeetCode solutions

2323. Minimum Bit Flips to Convert Number

My accepted Python solution to LeetCode problem 2323, Minimum Bit Flips to Convert Number, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.

python
class Solution:
    def minBitFlips(self, start: int, goal: int) -> int:
        # XOR gives us bits that are different
        # Count the number of 1 bits in XOR result
        # Time: O(log(max(start, goal))) = O(1), Space: O(1)
        xor = start ^ goal
        return bin(xor).count('1')

Source