Version #2 Sort
Version #1 HashSet
68.38 %
class Solution {
public boolean containsDuplicate(int[] nums) {
if (nums == null || nums.length <= 1) return false;
Set<Integer> visited = new HashSet<>();
for (int num : nums) {
if (!visited.add(num)) return true;
}
return false;
}
}
No comments:
Post a Comment