ByteByteGo: Swap Odd and Even Bits
β’ 45 words β’ 1 min
β’ updated
ByteByteGo: Swap Odd and Even Bits:
def swap_odd_and_even_bits(n: int) -> int:
ans = 0
shift = 0
while n > 0:
ans += ((n & 0b01) << 1) + ((n & 0b10) >> 1) << shift
n >>= 2
shift += 2
return ans
Related Posts
ByteByteGo: Product Array Without Current Element:
python from typing import List from functools import reduce import operator def β¦
Dec 02, 2025
ByteByteGo: K-Sum Subarrays:
python from typing import List import itertools def k_sum_subarrays(nums: List[int], k: int) -> int: acc = β¦
Dec 02, 2025
Previously, previously, previously, previously, previously.
Thiago Perrotta