Skip to content

Instantly share code, notes, and snippets.

@icameling
Last active July 18, 2022 08:06
Show Gist options
  • Save icameling/623887281e3cb6209496d47ae00767ae to your computer and use it in GitHub Desktop.
Save icameling/623887281e3cb6209496d47ae00767ae to your computer and use it in GitHub Desktop.
#数组 #移除元素 #leetcode
class Solution {
public:
int removeElement(vector<int>& nums, int val) {
auto iter = nums.begin();
for (;iter != nums.end();) {
if (*iter == val) {
iter = nums.erase(iter);
} else {
iter++;
}
}
return nums.size();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment