-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3158.go
More file actions
28 lines (24 loc) · 771 Bytes
/
solution3158.go
File metadata and controls
28 lines (24 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package solution3158
// ============================================================================
// 3158. Find the XOR of Numbers Which Appear Twice
// URL: https://leetcode.com/problems/find-the-xor-of-numbers-which-appear-twice/description/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3158---Find-the-XOR-of-Numbers-Which-Appear-Twice
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_duplicateNumbersXOR-24 197307122 6.008 ns/op 0 B/op 0 allocs/op
PASS
*/
func duplicateNumbersXOR(nums []int) int {
result := 0
freq := make([]int, 51)
for _, n := range nums {
freq[n]++
if freq[n] >= 2 {
result ^= n
}
}
return result
}