Remove Element (Leetcode)

PHOTO EMBED

Mon Oct 04 2021 07:37:20 GMT+0000 (Coordinated Universal Time)

Saved by @Sakshamkashyap7 #c++

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;
    }
};
content_copyCOPY

https://leetcode.com/problems/remove-element/