SUPER-SHORT C++,4ms


  • 0
    N
    class Solution {
    public:
        int removeElement(vector<int>& nums, int val) {
            int i=-1,d=-1,sz=nums.size();
            while(++i<sz) if(nums[i]!=val) nums[++d]=nums[i];
            return sz==0 ? 0 : d+1;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.