java simple solution using index


  • 0
    R
    public class Solution {
        public int removeDuplicates(int[] nums) {
            if(nums.length==0) return 0;
            int index=-1;
            for(int i=0;i<=nums.length-1;i++){
                if(index==-1||nums[i]!=nums[index]) nums[++index]=nums[i];
            }
            return index+1;
        }
    }
    

Log in to reply
 

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