Why my code is not correct?


  • 0
    I
    public class Solution 
    {
        public int removeDuplicates(int[] A) 
        {
            TreeSet<Integer> set = new TreeSet<Integer>();
            if(A.length == 0 || A.length == 1)
            {
                return A.length;
            }
            for(int num : A)
            {
                set.add(num);
            }
            A = new int[set.size()];
            int count = 0;
            for(int elem : set)
            {
                A[count] = elem;
                count++;
            }
            return set.size();
        }
    }

  • 0
    B

    You used a TreeSet which is an extra memory. But the problem ask for a "in-place" modification


Log in to reply
 

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