classSolution:defremoveElement(self,nums: List[int],val:int) ->int: left =0 right =len(nums)-1while left < right:while nums[right]== val and left < right: right -=1if nums[left]== val: nums[left], nums[right]= nums[right], nums[left] left +=1returnsum([1for num in nums if num != val])