clueless coding // TODO: be smarter

LeetCode Remove Element: CPP Solution



TL;DR Code Solution


int removeElement(vector<int>& nums, int val) {

    int insert = 0;

    for (int i = 0; i < nums.size(); i++) {
        if (nums[i] != val) {
            nums[insert++] = nums[i];
        }
    }

    return insert;

}