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.
解题心得:自己写的C的qsort因为没有CMP函数,不能使用,写了o(n2)的超时,自己实现的快排还不会,下次要学会,看了答案发现很多都是用了C++,JAVA的类库,就用Java做了
public class Solution {
public boolean containsDuplicate(int[] nums) {
boolean tag=false;
Arrays.sort(nums);
for(int i=0;i<nums.length-1;i++){
if(nums[i]==nums[i+1])
tag=true;
}
return tag;
}
}