public class Solution
{
public int removeDuplicates(int[] nums)
{
int dupes = 0;
for (int i = 1; i < nums.length; i++)
{
if (nums[i] == nums[i  1])
dupes++;
nums[i  dupes] = nums[i];
}
return nums.length  dupes;
}
}
Simple 1ms Java Solution

public static int removeDuplicates(int[] nums){ int numUnique = nums.length1; for (int i=0; i<nums.length1; i++) { int j=numUnique; while(i<j){ if (nums[i]==nums[j]) { //swap jth with the last item //let all duplicated item in behind. int temp = nums[numUnique]; nums[numUnique] = nums[j]; nums[j] = temp; numUnique; } j; } } return numUnique+1; }