public class Solution {
  public int removeDuplicates(int[] nums) {
    if (nums == null || nums.length == 0) return 0;
    int index = 0, counter = 1;
    for (int i = 1; i < nums.length; i++) {
      if (nums[i] > nums[i - 1]) {
        nums[++index] = nums[i];
        counter = 1;
      } else if (counter < 2) {
        // condition implies that nums[i] == nums[i - 1]
        nums[++index] = nums[i];
        counter++;
      }
    }
    return ++index;
  }
}

@@ -1,12 +1,255 @@
+// Solution runs in O(n) time and updates the input array in-place.%0A// Space complexity is O(1).%0A//%0A// Test cases:%0A//%0A// %5B1,1,1,2,2,3%5D%0A// %5B0,0,1,1,1,1,2,3,3%5D%0A// %5B0%5D%0A// %5B0,0%5D%0A// %5B0,1%5D%0A// %5B0,1,2,3,4,5,6%5D%0A// %5B1,1,1,1,1,1,2,3,4,4%5D%0A// %5B1,1,1,1,1%5D%0A%0A
 public class
@@ -702,8 +702,455 @@
 ;%0A  %7D%0A%7D%0A
+%0A// Another solution, similar logic, keep in mind that we update the counters after the check.%0Aclass Solution %7B%0A  public int removeDuplicates(int%5B%5D nums) %7B%0A    int idx = 0, dup = 0;%0A    for (int i = 1; i %3C nums.length; i++) %7B%0A      if (nums%5Bi%5D != nums%5Bidx%5D) %7B%0A        nums%5B++idx%5D = nums%5Bi%5D;%0A        dup = 0;%0A      %7D else if (nums%5Bi%5D == nums%5Bidx%5D && dup %3C 1) %7B%0A        nums%5B++idx%5D = nums%5Bi%5D;%0A        dup++;%0A      %7D%0A    %7D%0A%0A    return idx + 1;%0A  %7D%0A%7D%0A

update solution