217. 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.
思路
有无重复,是否存在 ->HashSet
出现次数 -> HashMap
题解
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> container = new HashSet<>();
for (int val : nums) {
if (container.contains(val))
return true;
container.add(val);
}
return false;
}
标签:217,container,val,Contains,Duplicate,return
From: https://www.cnblogs.com/tanhaoo/p/17035892.html