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
}