1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00
LeetCode/go/number-complement.go
Matej Focko c34927bd88
go: add «476. Number Complement»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-08-22 10:49:47 +02:00

11 lines
149 B
Go

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