217. Contains Duplicate
2017-07-22 本文已影响10人
DrunkPian0
幼儿园都会做
//0. O(n2)brute force
//1. sort
//2. map/set
public boolean containsDuplicate(int[] nums) {
Arrays.sort(nums);
for (int i = 1; i < nums.length; i++) {
if (nums[i] == nums[i - 1]) return true;
}
return false;
}