217. Contains Duplicate
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.
给定一个整数数组,判断数组中是否包含重复元素。如果数组中任意一个数字出现了至少两次,你的函数应该返回true,如果每一个元素都是唯一的,返回false。
1 public boolean containsDuplicate(int[] nums) { 2 if (nums.length < 2) return false; 3 Arrays.sort(nums); 4 for (int i=0;i<nums.length-1;i++) 5 { 6 if (nums[i] == nums[i+1]) return true; 7 } 8 return false; 9 }