def removeElement(self,nums,val): """ :type nums: List[int] :type val: int :rtype: int """ while val in nums: nums.remove(val) return len(nums)
A combination of remove() and while will make it quite easy to delete all the elements that are equal to val.
@qingpeng2 You are right bro. To be honest, this is the first problem I worked out and I did not realize how expensive these words are while writing lines. Now as I begin to have more exposure to a variety of problems here, I think I can get your point. Fortunately I did not get a "time limit exceeded" for this one lol.