6 ms simple java solution


  • 0
    S
    public boolean containsDuplicate(int[] nums) {
        if(nums.length == 0 || nums.length == 1){
            return false;
        }
        Arrays.sort(nums);
        int prev = Integer.MIN_VALUE;
        
        for(int x : nums){
            if(x!=prev){
                prev =x;
            }
            else{
                return true;
            }
        }
        return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.