leetcode/src/s0027_remove_element.cpp

19 lines
350 B
C++
Raw Normal View History

2022-11-15 07:38:15 +00:00
#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;
}