Java Solution


  • 0
    Z
    public List<Integer> findDuplicates(int[] nums) {
            List<Integer> res=new ArrayList();
            int[] list=new int[nums.length+1];
            for(int i=0;i<list.length;i++){
                list[i]=0;
            }
            
            for(int i=0;i<nums.length;i++){
                list[nums[i]]++;
            }
            
            for(int i=1;i<list.length;i++){
                if(list[i]>1) res.add(i);
            }
            
            return res;
            
        }
    

Log in to reply
 

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