Concise C++ code


  • 4
    int removeDuplicates(vector<int>& nums) {
        int i = 0;
        for( int j=1; j<nums.size(); j++ ) {
            if( nums[j] != nums[j-1]) 
                nums[++i] = nums[j];
        }
        return nums.empty() ? 0 : i+1;
    }

Log in to reply
 

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