Why my solution is wrong


  • 0
    C
    class Solution:
        # @param a list of integers
        # @return an integer
        def removeDuplicates(self, A):
    		if A == []:
    			return(0)
    		count = 1;
    		for i in range(1,len(A)):
    			if A[i] != A[i-1]:
    				count += 1
    		return(count)

  • 0
    Y

    You didn't remove the duplicates from your array.
    e.g. if the input is
    1,1,2
    you need to make it like:
    1,2,2 with count = 2 (since we can't really delete elements from array, just leave the last elements there but somewhat treat the valid array size as 2)


  • 0
    C

    Yes, thank you very much, now I have solved this problem


Log in to reply
 

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