leetcode/src/s0027_remove_element.cpp
2022-11-30 18:20:36 +08:00

15 lines
250 B
C++

#include "s0027_remove_element.hpp"
int S0027::removeElement(vector<int>& nums, int val) {
int len = nums.size();
int f{0}, s{0};
while (f < len) {
if (nums[f] != val) {
nums[s] = nums[f];
++s;
}
++f;
}
return s;
}