Straight forward C++


  • 0
    C
    int removeDuplicates(vector<int>& nums) {
        int length=nums.size();
        if (length==0) return 0;
        int working=0;
        int lastvalue=nums[0];
        for(int checking=0;checking<length;checking++){
            if(nums[checking]!=lastvalue){
                nums[working++]=lastvalue;
                lastvalue=nums[checking];
            }
        }
        if(nums[length-1]==lastvalue){
            nums[working++]=lastvalue;
        }
        return working;
        
    }

Log in to reply
 

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