Java simple solution, enjoy!


  • 0
    M
        public int removeDuplicates(int[] nums) {
            if(nums.length==0)
                return 0;
            int count=1;
            
            int len =nums.length;
            for(int i=1; i<nums.length; i++){
                if(nums[i]==nums[i-1]){
                    continue;
                }
                else{
                	nums[count]=nums[i];
                	count++;
                	}
                
                
            }
            return count;
        }
    

Log in to reply
 

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