go: add «476. Number Complement»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-08-22 10:49:47 +02:00
parent a3fca26cdd
commit c34927bd88
No account linked to committer's email address

11
go/number-complement.go Normal file
View file

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