Easy Java Solution


  • 0
    A
    public class Solution {
        public List<Integer> findDuplicates(int[] nums) {
            List<Integer> ans = new ArrayList<Integer>();
            Arrays.sort(nums);
            for(int i =0;i<nums.length-1;i++)
                if(nums[i]==nums[i+1]) ans.add(nums[i]);
            return ans;
        }
    }
    

Log in to reply
 

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