Thi is very strange, here is my python code:
When I run it on my own computer, it gives me the correct answer.
When I run it in LeetCode, it gives me a different wrong answer.
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): A = filter(lambda e: e!=elem, A) return len(A)
By this means, you created a new variable A rather than the one given by input since it asked to remove element in place.
You might try A[ : ] = filter(lambda e: e!=elem, A)