LeetCode 27. Remove Element Posted on 2021-04-20 Edited on 2024-11-24 In LeetCode 123456789101112class Solution {public: int removeElement(vector<int>& nums, int val) { int i = 0, j = 0; for (int num : nums) { if (num != val) nums[i++] = num; ++j; } return i; }};