Java solution for duplication appear any times!

  • 0
    //intial an array count for the appearance of duplications
    public List<Integer> findDuplicates(int[] nums) {
            int[] count=new int[nums.length+1];
            List<Integer> list=new ArrayList<>();
            for(int i=0;i<nums.length;i++){
            for(int j=1;j<count.length;j++){
                if(count[j]==2) list.add(j);
            return list;

Log in to reply

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