Code works, but running time is too long


  • 0
    K

    Hello, my code works but the running time is too long, how can I reduce running time here?

    int removeDuplicates(vector<int>& nums) {
            for (int i = 0; i < nums.size() - 1; i++) {
    		while (i != nums.size() -1 && nums[i] == nums[i + 1]) {
    			for (int j = i + 1; j < nums.size() - 1; j++)
    				nums[j] = nums[j + 1];
    			nums.pop_back();
    		}
    	}
    
    	return nums.size();
            
        }
    
    

Log in to reply
 

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