Leetcode 201 Bitwise AND of Numbers Range Solution in java | Hindi Coding Community

0

 


Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive.


Example 1:


Input: left = 5, right = 7

Output: 4

Example 2:


Input: left = 0, right = 0

Output: 0


 
public int rangeBitwiseAnd(int m, int n) {
        return m < n ? rangeBitwiseAnd(m, n & n-1) : n;
    }

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !