leetcode/src/s0027_remove_element.cpp

15 lines
250 B
C++
Raw Normal View History

2022-11-15 07:38:15 +00:00
#include "s0027_remove_element.hpp"
2022-11-30 10:20:36 +00:00
int S0027::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
}