217--存在重复元素
方法一:排序,对数组排序,如果存在重复元素,则数组相邻元素一定相等。
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> set = new HashSet<Integer>();
for (int x : nums) {
if (!set.add(x)) {
return true;
}
}
return false;
}
}