12345678910111213141516171819202122 |
- from typing import List
- import pytest
- def removeElement(nums: List[int], val: int):
- i = 0
- while i < len(nums):
- if nums[i] == val:
- nums.remove(nums[i])
- else:
- i += 1
- return len(nums)
- @pytest.mark.parametrize(
- "nums, val, expect",
- [
- ([-2, 3, 1, 5], 3, 3),
- ([2, 3, 3, 2], 3, 2)
- ]
- )
- def test_cases(nums, val, expect):
- assert removeElement(nums, val) == expect
|