remove_element.py 441 B

12345678910111213141516171819202122
  1. from typing import List
  2. import pytest
  3. def removeElement(nums: List[int], val: int):
  4. i = 0
  5. while i < len(nums):
  6. if nums[i] == val:
  7. nums.remove(nums[i])
  8. else:
  9. i += 1
  10. return len(nums)
  11. @pytest.mark.parametrize(
  12. "nums, val, expect",
  13. [
  14. ([-2, 3, 1, 5], 3, 3),
  15. ([2, 3, 3, 2], 3, 2)
  16. ]
  17. )
  18. def test_cases(nums, val, expect):
  19. assert removeElement(nums, val) == expect