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:
Matej Focko 2025-01-16 16:40:16 +01:00
parent e02c4fda66
commit 9565215eba
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

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