public class Solution { public int removeDuplicates(int[] nums) { int size=nums.length; int last=0; boolean isHead=true; int lastIndex=0; for(int i=0;i<size;i++) { int temp=nums[i]; if(isHead==true) { isHead=false; lastIndex++; } else { if(last!=nums[i]) { if(lastIndex!=i) nums[lastIndex]=nums[i]; lastIndex++; } } last=temp; } return lastIndex; } }