Last active
July 18, 2022 08:06
-
-
Save icameling/623887281e3cb6209496d47ae00767ae to your computer and use it in GitHub Desktop.
#数组 #移除元素 #leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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