-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisJointArray.java
More file actions
35 lines (32 loc) · 802 Bytes
/
DisJointArray.java
File metadata and controls
35 lines (32 loc) · 802 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
29
30
31
32
33
34
35
package datastructure.hashtable;
import java.util.HashSet;
/**
* The type Dis joint array.
*/
public class DisJointArray {
/**
* Is dis joint boolean.
*
* @param arr1 the arr 1
* @param arr2 the arr 2
* @return the boolean
*/
public static boolean isDisJoint(int[] arr1, int[] arr2) {
HashSet<Integer> set = new HashSet<>();
for (int i : arr1)
set.add(i);
for (int i : arr2)
if (set.contains(i)) return false;
return true;
}
/**
* Main.
*
* @param args the args
*/
public static void main(String args[]) {
int arr1[] = {1, 3, 6, 9, 12, 15, 18, 21};
int arr2[] = {5, 10, 19};
System.out.println("Is Disjoint :: " + isDisJoint(arr1, arr2));
}
}