Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
HashSet seconds
public class Solution { public boolean containsDuplicate(int[] nums) { Set set = new HashSet(); for(int i : nums) if(!set.add(i))// if there is same return true; return false; } } This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:「LeetCode – 217. Contains Duplicate」