mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-24 10:37:33 +08:00
24 lines
314 B
Go
24 lines
314 B
Go
package leetcode
|
|
|
|
func findTheDistanceValue(arr1 []int, arr2 []int, d int) int {
|
|
res := 0
|
|
for i := range arr1 {
|
|
for j := range arr2 {
|
|
if abs(arr1[i]-arr2[j]) <= d {
|
|
break
|
|
}
|
|
if j == len(arr2)-1 {
|
|
res++
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
}
|
|
|
|
func abs(a int) int {
|
|
if a < 0 {
|
|
return -1 * a
|
|
}
|
|
return a
|
|
}
|