题目链接
Set实现
Map实现
class Solution {
public boolean containsDuplicate(int[] nums) {
int len = nums.length;
Map<Integer,Integer> map = new HashMap<>(len);
for(int i = 0;i<len;i++){
if(map.containsKey(nums[i])){
return true;
}
map.put(nums[i],i);
}
return false;
}
}