-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistanceBetweenArrays.java
More file actions
39 lines (31 loc) · 1.04 KB
/
Copy pathDistanceBetweenArrays.java
File metadata and controls
39 lines (31 loc) · 1.04 KB
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
37
38
39
package LeetcodePractice;
public class DistanceBetweenArrays {
public static int findTheDistanceValue(int[] arr1, int[] arr2, int d) {
int count = 0;
for (int num1 : arr1) {
boolean isValid = true;
for (int num2 : arr2) {
if (Math.abs(num1 - num2) <= d) {
isValid = false;
break;
}
}
if (isValid) {
count++;
}
}
return count;
}
public static void main(String[] args) {
int[] arr1 = {4, 5, 8};
int[] arr2 = {10, 9, 1, 8};
int d = 2;
System.out.println(findTheDistanceValue(arr1, arr2, d));
int[] arr3 = {1, 4, 2, 3};
int[] arr4 = {-4, -3, 6, 10, 20, 30};
System.out.println(findTheDistanceValue(arr3, arr4, 3));
int[] arr5 = {2, 1, 100, 3};
int[] arr6 = {-5, -2, 10, -3, 7};
System.out.println(findTheDistanceValue(arr5, arr6, 6));
}
}