Java : Simple Solution 28 / 28 test cases passed


  • 0
            
            ArrayList<Integer> arr = new ArrayList<>();
            Arrays.sort(nums);
            
            if(nums.length <1) return arr;
            
            for(int i=0;i<nums.length-1;i++){
                if(nums[i]==nums[i+1]) arr.add(nums[i]);
            }
            return arr;
        }
    

Log in to reply
 

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