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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-29.
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')