# 80. Remove Duplicates from Sorted Array II

```java
class Solution {
    public int removeDuplicates(int[] nums) {
        int firstPointer = 1;
        int result = 1;
        int currentVal = nums[0];
        int currentValCount = 1;
        // i is the second pointer
        for(int i=1; i<nums.length; i++){
            if (currentVal!=nums[i]){
                currentVal=nums[i];
                currentValCount =1;
                if(firstPointer<i) nums[firstPointer] = nums[i];
                firstPointer++;
                result++;
                
                // currentVal==nums[i] && currentValCount ==1
            }else if (currentValCount==1){
                currentValCount++;
                if(firstPointer<i) nums[firstPointer] = nums[i];
                firstPointer++;
                result++;
            }
            // if currentVal==nums[i] && currentValCount == 2, 
            // i++ and do nothing
        }
        return result;
    }
}
```
