Skip to content

Commit f5161b5

Browse files
committed
Union Size of Array
1 parent ac6c6b2 commit f5161b5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Hashing/UnionOfArray.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package SummerTrainingGFG.Hashing;
2+
3+
import java.util.HashSet;
4+
5+
/**
6+
* @author Vishal Singh
7+
* Return distinct union size of the arrays*/
8+
public class UnionOfArray {
9+
static int union(int[] a,int[] b,int aSize,int bSize){
10+
HashSet<Integer> set = new HashSet<>();
11+
for (int i = 0; i < aSize; i++) {
12+
set.add(a[i]);
13+
}
14+
for (int i = 0; i < bSize; i++) {
15+
set.add(b[i]);
16+
}
17+
return set.size();
18+
}
19+
public static void main(String[] args) {
20+
int[] a = {15,20,5,15};
21+
int[] b = {15,15,15,20,10};
22+
System.out.println("Distinct Size of Union of array is: "+union(a,b,a.length,b.length));
23+
}
24+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Java Solution for Data Structures and Algorithms.
121121
* [Count Distinct Elements](Hashing/CountDistinctElements.java)
122122
* [Frequency Of Array Elements](Hashing/FrequencyOfArrayElements.java)
123123
* [Intersection Of Array](Hashing/InsertionOfArray.java)
124+
* [Union of Array](Hashing/UnionOfArray.java)
124125

125126
### `NOTE: Raise an issue if any program doesn't work.`
126127
### `More Topics to be added soon`

0 commit comments

Comments
 (0)