Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Jan 16, 2025
1 parent cfb087f commit b2759cf
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions leetcode/daily/2425/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/

package main

import "fmt"

// TLE
func xorAllNums(nums1 []int, nums2 []int) int {
n := len(nums1)
m := len(nums2)

res := 0

for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
res ^= nums1[i] ^ nums2[j]
}
}

return res
}

func xorAllNums1(nums1 []int, nums2 []int) int {
n := len(nums1)
m := len(nums2)

xor1, xor2 := 0, 0

for i := 0; i < n; i++ {
xor1 ^= nums1[i]
}

for i := 0; i < m; i++ {
xor2 ^= nums2[i]
}

if n%2 == 0 && m%2 == 0 {
return 0
} else if n%2 == 0 {
return xor1
} else if m%2 == 0 {
return xor2
} else {
return xor1 ^ xor2
}
}

func main() {
nums1 := []int{1, 2}
nums2 := []int{3, 4}

// nums1 := []int{2, 1, 3}
// nums2 := []int{10, 2, 5, 0}

fmt.Println(xorAllNums1(nums1, nums2))
}

0 comments on commit b2759cf

Please sign in to comment.