go: add «2425. Bitwise XOR of All Pairings»
URL: https://leetcode.com/problems/bitwise-xor-of-all-pairings/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
e02c4fda66
commit
9565215eba
1 changed files with 19 additions and 0 deletions
19
go/bitwise-xor-of-all-pairings.go
Normal file
19
go/bitwise-xor-of-all-pairings.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
func xorAllNums(nums1 []int, nums2 []int) int {
|
||||
xorFold := func(nums []int, otherLength int) int {
|
||||
acc := 0
|
||||
if otherLength%2 == 0 {
|
||||
return acc
|
||||
}
|
||||
|
||||
for _, num := range nums {
|
||||
acc ^= num
|
||||
}
|
||||
|
||||
return acc
|
||||
}
|
||||
|
||||
xor1, xor2 := xorFold(nums1, len(nums2)), xorFold(nums2, len(nums1))
|
||||
return xor1 ^ xor2
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue