bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 201. Bitwise AND of Numbers Range

201. Bitwise AND of Numbers Range

Leetcode Solutions

Bit Shift Approach for Range Bitwise AND

  1. Initialize a variable shift to 0, which will keep track of the number of shifts performed.
  2. While left is not equal to right: a. Right-shift both left and right by 1. b. Increment shift by 1.
  3. Left-shift left by shift positions to restore it to its original position but with trailing zeros.
  4. Return the shifted left as the result.
UML Thumbnail

Brian Kernighan's Algorithm for Range Bitwise AND

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...