class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> seen = new HashSet<>();
for(int i=0; i<nums.length; i++) {
if(seen.contains(nums[i])) { // methods: add(), contains(), remove()
return true;
} else {
seen.add(nums[i]);
}
}
return false;
}
}
No comments:
Post a Comment