single-number-iii

This commit is contained in:
Gleb Koval 2021-11-10 15:12:32 +00:00
parent a9f0806793
commit dbe344221b
No known key found for this signature in database
GPG Key ID: DF27F6A77C48FDA0
1 changed files with 18 additions and 0 deletions

18
single-number-iii/sol.go Normal file
View File

@ -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
}