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 <= 105class Solution {
fun consecutiveSetBits(n: Int): Boolean {
var n = n
var cnt = 0
while (n != 0) {
if ((n and 3) == 3) {
cnt++
}
n = n shr 1
}
return cnt == 1
}
}