clueless coding // TODO: be smarter

LeetCode Remove Duplicates from Sorted Array: CPP Solution



TL;DR Code Solution


int removeDuplicates(vector<int>& nums) {

    int insert = 0;

    for (int i = 0; i < nums.size(); i++) {

        if (i == 0 || nums[i] != nums[i - 1]) {
            nums[insert] = nums[i];
            insert++;
        }

    }

    return insert;





}