Posted on

Description

Submission

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int j = 0;
        for(int i = 0; i < nums.size(); ++i) {
            if(nums[i] != val) nums[j++] = nums[i];
        }
        return j;
    }
};

Submission 210429

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int i = 0, j = 0;

        for(; j < nums.size(); ++j) {
            if(nums[j] == val) continue;
            nums[i++] = nums[j]; 
        }

        return i;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *