Untitled
unknown
java
a year ago
1.0 kB
6
Indexable
import java.util.*;
class IntSet {
private TreeSet<Integer> ts;
public IntSet(int[] a)
{
for(int val: a)
ts.add(val);
}
public IntSet union(IntSet other)
{
IntSet res = new IntSet(new int[0]);
res.ts.addAll(this.ts);
res.ts.addAll(other.ts);
return res;
}
@Override
public String toString() {
String result = "";
for (int x : ts) {
result += x;
}
return result;
}
}
public class J04021 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m = sc.nextInt(), a[] = new int[n], b[] = new int[m];
for(int i = 0; i<n; i++) a[i] = sc.nextInt();
for(int i = 0; i<m; i++) b[i] = sc.nextInt();
IntSet s1 = new IntSet(a);
IntSet s2 = new IntSet(b);
IntSet s3 = s1.union(s2);
System.out.println(s3);
}
}
Editor is loading...
Leave a Comment