1. Contains Duplicate
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.
Code
class Solution {
public boolean containsDuplicate(int[] nums) {
HashMap<Integer, Integer> duplicateHashmap = new HashMap<Integer, Integer>();
for (int index = 0; index < nums.length; index++) {
if (duplicateHashmap.containsKey(nums[index])) {
return true;
} else {
duplicateHashmap.put(nums[index], 1);
}
}
return false;
}
}Last updated