Link Search Menu Expand Document

217. Contains Duplicate

Solution Code

Java

class Solution {
    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;
    }
}

© 2023. All rights reserved.