27. Remove Element ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10 11 12class Solution { public: int removeElement(vector<int>& nums, int val) { int i = 0; for (const int num : nums) if (num != val) nums[i++] = num; return i; } }; 1 2 3 4 5 6 7 8 9 10 11class Solution { public int removeElement(int[] nums, int val) { int i = 0; for (final int num : nums) if (num != val) nums[i++] = num; return i; } } 1 2 3 4 5 6 7 8 9 10class Solution: def removeElement(self, nums: list[int], val: int) -> int: i = 0 for num in nums: if num != val: nums[i] = num i += 1 return i