clueless coding // TODO: be smarter

LeetCode Remove Duplicates from Sorted Array II: CPP Solution



TL;DR Code Solution


int removeDuplicates(vector<int>& nums) {

    int insert = 0;
    for (int num : nums) {
        if (insert < 2 || num > nums[insert - 2]) {
            nums[insert++] = num;
        }
    }
    return insert;

}