mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-02-27 03:38:08 +08:00
190, 3379, 693
This commit is contained in:
16
26/02/190.go
Normal file
16
26/02/190.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package A
|
||||
|
||||
import "math/bits"
|
||||
|
||||
func reverseBits(n int) int {
|
||||
res := 0
|
||||
for i := 0; i < 32; i++ {
|
||||
res = (res << 1) | (n & 1)
|
||||
n >>= 1
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func reverseBits2(n int) int {
|
||||
return int(bits.Reverse32((uint32(n))))
|
||||
}
|
||||
6
26/02/693.go
Normal file
6
26/02/693.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package A
|
||||
|
||||
func hasAlternatingBits(n int) bool {
|
||||
n = n ^ (n >> 1)
|
||||
return n&(n+1) == 0
|
||||
}
|
||||
Reference in New Issue
Block a user