Easy
You are given an integer n.
Return true if its binary representation contains exactly one adjacent pair of set bits, and false otherwise.
Example 1:
Input: n = 6
Output: true
Explanation:
110."11"). Thus, the answer is true.Example 2:
Input: n = 5
Output: false
Explanation:
101.false.Constraints:
0 <= n <= 105public class Solution {
public boolean consecutiveSetBits(int n) {
int cnt = 0;
while (n != 0) {
if ((n & 3) == 3) {
cnt++;
}
n = n >> 1;
}
return cnt == 1;
}
}