1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00
LeetCode/go/number-complement.go

12 lines
149 B
Go
Raw Normal View History

package main
func findComplement(num int) int {
mask := 0
for tmp := num; tmp != 0; tmp >>= 1 {
mask <<= 1
mask |= 1
}
return num ^ mask
}