27. Remove Element
O(n)
from typing import List

class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        i = 0
        j = len(nums) -1

        while i <= j:
            if nums[i] != val:
                i += 1
            else:
                nums[i] = nums[j]
                j -= 1

        nums = nums[:j+1]
        print(nums)

        return len(nums)

def main():
    s = Solution()

    print(s.removeElement([3,2,2,3], 3)) # 2
    print(s.removeElement([0,1,2,2,3,0,4,2], 2)) #5
    print(s.removeElement([1], 1)) # 0

if __name__ == '__main__':
    main()