Bitwise AND of Numbers Range

Medium

Topics
Bit Manipulation

Given two integers a and b with a <= b, return the bitwise AND of all numbers in the inclusive range [a, b].

Example 1

Input:  a = 5, b = 7
Output: 4

Example 2

Input:  a = 0, b = 0
Output: 0

Example 3

Input:  a = 26, b = 30
Output: 24

Constraints

  • 0 <= a <= b <= 2^31 - 1
Run ⌘' · Submit ⌘⏎