File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments