Range Bitwise AND
Solution ApproachWas this helpful?
Medium•bits•Expected: O(log n) time, O(1) space
prefix-sumbit-manipulation
Problem
Given two integers left and right representing a range [left, right], return the bitwise AND of all numbers in this range.
Example 1:
Input: left = 5, right = 7
Output: 4
Explanation: 5 (101) & 6 (110) & 7 (111) = 4 (100)
Example 2:
Input: left = 0, right = 0
Output: 0
Example 3:
Input: left = 1, right = 2147483647
Output: 0
Reference solution unlocks after your first submission
Loading...
