class Solutions {
//217.存在重复元素
public boolean containsDuplicate(int[] nums) {
if (nums.length == 0) {
return false;
}
Set<Integer> hashset = new HashSet<>(nums.length);
for (int i = 0; i < nums.length - 1; i++) {
if (hashset.contains(nums[i])) {
return true;
}
hashset.add(nums[i]);
}
return false;
}
}
原文:https://www.cnblogs.com/hanhande/p/12805882.html