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.
书看的头疼,上来刷两道。加州的破网也是无力吐槽,家里的网慢就算了,马德学校的网也卡!!。
Solution1:
思路:解法太多了,来两种。
public class Solution { public boolean containsDuplicate(int[] nums) { if(nums.length==0||nums.length==1) { return false; } Arrays.sort(nums); for(int i=1;i
Solution2:
HashSet要考虑一下resize的问题,给它定义一个容量即可。
public class Solution { public boolean containsDuplicate(int[] nums) { Setcheck=new HashSet (nums.length); for(int i=0;i