class Solution {
public:
int removeElement(vector<int>& nums, int val) {
int start = 0, end = nums.size(),ans=0;
while(start < end) {
if(nums[start] == val) {
swap(nums[start],nums[end-1]);
end--;
}
else start++;
}
return end;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter