Java Solution


  • 0
    C
    class Solution {
        public int removeDuplicates(int[] nums) {
    		int duplicateNum = 0;
    		int index = 0;
    		int frequency = 0;
    		for(int i = 1 ; i < nums.length ; i++){
    			if(nums[index]==nums[i]){
    				if(frequency==0){
    					frequency++;
    					index++;
    					nums[index]=nums[i];
    				}else{
    					duplicateNum++;
    				}
    			}else{
    				frequency = 0;
    				index++;
    				nums[index]=nums[i];
    			}	
    		}
            return nums.length-duplicateNum;
        }
    }
    

Log in to reply
 

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