
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 len(A) == 0:
    	    return 0
        else:
            k=0
            for i in range(0, len(A)):
                if A[i] != elem:
                    A[k] = A[i]
                    k += 1
            return k


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 len(A) == 0:
    	    return 0
        else:
            k=0
            for i in range(0, len(A)):
                if A[i] != elem:
                    if i!= k:
                        A[k] = A[i]
                    k += 1
            return k

Add one more if to speed up
Add one more if to speed up
  
  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 len(A) == 0:
      	    return 0
          else:
              k=0
              for i in range(0, len(A)):
                  if A[i] != elem:
+                     if i!= k:
-                     A[k] = A[i]
+                         A[k] = A[i]
                      k += 1
              return k
  
Add one more if to speed up
## Code Before:

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 len(A) == 0:
    	    return 0
        else:
            k=0
            for i in range(0, len(A)):
                if A[i] != elem:
                    A[k] = A[i]
                    k += 1
            return k

## Instruction:
Add one more if to speed up
## Code After:

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 len(A) == 0:
    	    return 0
        else:
            k=0
            for i in range(0, len(A)):
                if A[i] != elem:
                    if i!= k:
                        A[k] = A[i]
                    k += 1
            return k
