-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution2932.go
36 lines (30 loc) · 886 Bytes
/
solution2932.go
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
29
30
31
32
33
34
35
36
package solution2932
import (
"math"
)
// ============================================================================
// 2932. Maximum Strong Pair XOR I
// URL: https://leetcode.com/problems/maximum-strong-pair-xor-i/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/2932---Maximum-Strong-Pair-XOR-I
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
BenchmarkMaximumStrongPairXor
BenchmarkMaximumStrongPairXor-24 25561774 46.92 ns/op 0 B/op 0 allocs/op
PASS
*/
func maximumStrongPairXor(nums []int) int {
var v, m, maxXor int
for i := 0; i < len(nums); i++ {
for j := 0; j < len(nums); j++ {
v = int(math.Abs(float64(nums[i]) - float64(nums[j])))
if v <= min(nums[i], nums[j]) {
maxXor = nums[i] ^ nums[j]
m = max(m, maxXor)
}
}
}
return m
}