16 lines
296 B
Go
16 lines
296 B
Go
// Package q693 implements a solution for https://leetcode.com/problems/binary-number-with-alternating-bits/
|
|
package q693
|
|
|
|
func hasAlternatingBits(n int) bool {
|
|
last := -1
|
|
for n > 0 {
|
|
if last == n%2 {
|
|
return false
|
|
}
|
|
last = n % 2
|
|
n >>= 1
|
|
}
|
|
return true
|
|
}
|
|
|
|
var _ = hasAlternatingBits
|