Description
给定2 个集合S和T,试设计一个判定S和T是否相等的蒙特卡罗算法。
设计一个拉斯维加斯算法,对于给定的集合S和T,判定其是否相等。
Input
输入数据的第一行有1 个正整数n(n≤10000),表示集合的大小。接下来的2行,每行有n个正整数,分别表示集合S和T中的元素。
Output
将计算结论输出。集合S和T相等则输出YES,否则输出NO。
Sample
Input
3
2 3 7
7 2 3
Output
YES
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Set<Integer> S = new HashSet<Integer>();
Set<Integer> T = new HashSet<Integer>();
int n = input.nextInt();
for(int i=0; i<n; i++) {
S.add(input.nextInt());
}
for(int i=0; i<n; i++) {
T.add(input.nextInt());
}
if(S.equals(T))
System.out.println("YES");
else
System.out.println("NO");
input.close();
}
}