mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-06-04 02:21:15 +08:00
routine
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"math/bits"
|
||||
)
|
||||
|
||||
func bitwiseComplement(n int) int {
|
||||
if n == 0 {
|
||||
return 1
|
||||
}
|
||||
return n ^ (1<<bits.Len(uint(n)) - 1)
|
||||
}
|
||||
Reference in New Issue
Block a user