Home:ALL Converter>Remove Duplicates from Sorted Array Leetcode

Remove Duplicates from Sorted Array Leetcode

Ask Time:2021-09-18T03:33:16         Author:Roshan Choudhary

Json Formatter

Below are my code implementation :

class Solution {
    public int removeDuplicates(int[] nums){
        
        List<Integer> list = Arrays.stream(nums).boxed().collect(Collectors.toList());        
        Set<Integer> set = new LinkedHashSet<>(list);
        return set.size();
    }
}

The easiest way to remove duplicates . But still not accepted in leetcode.

Can anyone help me to know is this solution right ? If Yes, then what is the problem ?

Author:Roshan Choudhary,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69228630/remove-duplicates-from-sorted-array-leetcode
yy