Simple python solution 55ms


  • 0
    L
    class Solution:
        # @param    A       a list of integers
        # @param    elem    an integer, value need to be removed
        # @return an integer
        def removeElement(self, A, elem):
            if not A:
                return 0
            n = 0
            for i in range(len(A)):
                if A[i] != elem:
                    A[n] = A[i]
                    n += 1
            return n

Log in to reply
 

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