Skip to content

Commit b2759cf

Browse files
committed
add sol
1 parent cfb087f commit b2759cf

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

leetcode/daily/2425/sol.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/
2+
3+
package main
4+
5+
import "fmt"
6+
7+
// TLE
8+
func xorAllNums(nums1 []int, nums2 []int) int {
9+
n := len(nums1)
10+
m := len(nums2)
11+
12+
res := 0
13+
14+
for i := 0; i < n; i++ {
15+
for j := 0; j < m; j++ {
16+
res ^= nums1[i] ^ nums2[j]
17+
}
18+
}
19+
20+
return res
21+
}
22+
23+
func xorAllNums1(nums1 []int, nums2 []int) int {
24+
n := len(nums1)
25+
m := len(nums2)
26+
27+
xor1, xor2 := 0, 0
28+
29+
for i := 0; i < n; i++ {
30+
xor1 ^= nums1[i]
31+
}
32+
33+
for i := 0; i < m; i++ {
34+
xor2 ^= nums2[i]
35+
}
36+
37+
if n%2 == 0 && m%2 == 0 {
38+
return 0
39+
} else if n%2 == 0 {
40+
return xor1
41+
} else if m%2 == 0 {
42+
return xor2
43+
} else {
44+
return xor1 ^ xor2
45+
}
46+
}
47+
48+
func main() {
49+
nums1 := []int{1, 2}
50+
nums2 := []int{3, 4}
51+
52+
// nums1 := []int{2, 1, 3}
53+
// nums2 := []int{10, 2, 5, 0}
54+
55+
fmt.Println(xorAllNums1(nums1, nums2))
56+
}

0 commit comments

Comments
 (0)