1 2 3 4 5 6 7 8 9 10 11 // @Title: 交替位二进制数 (Binary Number with Alternating Bits) // @Author: 15816537946@163.com // @Date: 2022-03-28 23:15:37 // @Runtime: 0 ms // @Memory: 1.9 MB func hasAlternatingBits(n int) bool { a := n ^ n>>1 return a&(a+1) == 0 }