My Simple Java Solution without Set


  • 0
    H
    public boolean containsDuplicate(int[] nums) {
        if(nums.length==1||nums.length==0)
        return false;
        Arrays.sort(nums);
        int temp=nums[0];
        for(int i=1;i<nums.length;i++){
            if(temp==nums[i]){
                return true;
            }else{
                temp=nums[i];
            }
        }
        return false;
    }

Log in to reply
 

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