2022-11-15 07:38:15 +00:00
|
|
|
#include "s0027_remove_element.hpp"
|
|
|
|
|
|
|
|
int Solution::removeElement(vector<int>& nums, int val) {
|
2022-11-24 09:21:25 +00:00
|
|
|
int len = nums.size();
|
|
|
|
int f{0}, s{0};
|
|
|
|
while (f < len) {
|
|
|
|
if (nums[f] != val) {
|
|
|
|
nums[s] = nums[f];
|
|
|
|
++s;
|
2022-11-15 07:38:15 +00:00
|
|
|
}
|
2022-11-24 09:21:25 +00:00
|
|
|
++f;
|
2022-11-15 07:38:15 +00:00
|
|
|
}
|
2022-11-24 09:21:25 +00:00
|
|
|
return s;
|
2022-11-15 07:38:15 +00:00
|
|
|
}
|