Solution 1: easy hash problem
public class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> set=new HashSet<>();
for (int x:nums) {
if (set.contains(x)) return true;
else set.add(x);
}
return false;
}
}
没有评论:
发表评论