single-number-iii
This commit is contained in:
parent
a9f0806793
commit
dbe344221b
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
func singleNumber(nums []int) []int {
|
||||
xor := 0
|
||||
for i := range nums {
|
||||
xor ^= nums[i]
|
||||
}
|
||||
xor &= -xor
|
||||
out := []int{0, 0}
|
||||
for i := range nums {
|
||||
if nums[i]&xor == 0 {
|
||||
out[0] ^= nums[i]
|
||||
} else {
|
||||
out[1] ^= nums[i]
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
Loading…
Reference in New Issue