1. Title
Contains Duplicate
2. Http address
https://leetcode.com/problems/contains-duplicate/
3. The question
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.
4. My code(AC)
1 // Accepted 2 public static boolean containsDuplicate(int[] nums) { 3 4 if ( nums == null || nums.equals("")) 5 return false; 6 Arrays.sort(nums); 7 int len = nums.length; 8 for( int i = 1 ; i < len ; i++) 9 { 10 if( nums[i] == nums[i-1]) 11 return true; 12 } 13 return false; 14 }