Checking Binary Alternation in Java

Day 49: Keeping the rhythm with Binary! 🎶 Problem 693: Binary Number with Alternating Bits Today was a smooth one. The challenge: check if a number's binary representation has alternating 0s and 1s with no two adjacent bits being the same. My approach: 1. Converted the integer to a binary string. 2. Ran a linear scan to compare each bit with its neighbor. 3. If any match? Immediate false. It’s a clean O(logN) solution. While there are some "galaxy brain" bitwise tricks to solve this in one line, sometimes a clear string traversal is all you need to keep the streak alive. No nested nightmares today. 🚀 #LeetCode #Java #Binary #CodingChallenge #ProblemSolving #Algorithms

  • text

To view or add a comment, sign in

Explore content categories