LeetCode Solutions/February 2022 LeetCoding Challenge/Remove Duplicates from Sorted Array II.java
class Solution {
    public int removeDuplicates(int[] nums) {
        int i = 0;
        for (int j : nums) {
            if (i < 2 || nums[i-2] < j) {
                nums[i++] = j;
            }
        }
        return i;
    }
}