19 lines
350 B
C++
19 lines
350 B
C++
|
#include "s0027_remove_element.hpp"
|
||
|
|
||
|
int Solution::removeElement(vector<int>& nums, int val) {
|
||
|
int size = nums.size();
|
||
|
if (size == 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
int fast{0}, slow{0};
|
||
|
for (; fast < size; ++fast) {
|
||
|
if (nums.at(fast) == val) {
|
||
|
continue;
|
||
|
} else {
|
||
|
nums[slow] = nums.at(fast);
|
||
|
++slow;
|
||
|
}
|
||
|
}
|
||
|
return slow;
|
||
|
}
|