mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-14 01:49:41 +01:00
11 lines
149 B
Go
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
|
|
}
|