classSolution {publicintremoveDuplicates(int[] nums) {int n =nums.length;int i, j =1;for (i =0; i < n ; i++) {while (j < n && nums[j] == nums[i]) { j++; } if (j == n) {break; } nums[i+1] = nums[j]; }return i+1; }}/*[0,1,2,3,4,2,2,3,3,4] j i so the ans is i+1*/
more easier way
because when number are different, set number to front, so...
้็ i, ๅฐฑๅไธไธๅๅๆณ็ j, count ๅฐฑๅไธไธๅๅๆณ็ i