Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
- Create Set loop through array if it exists then true else false
Time: O(n) Space: O(n)
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> duplicate = new HashSet<>();
for(int num: nums) {
if(duplicate.contains(num)) {
return true;
}
duplicate.add(num);
}
return false;
}
}