Remove Duplicates II (Allowed Twice)

Given a sorted array `nums`, remove duplicates in-place such that duplicates appeared at most twice. Return the new length of the modified array.

Input Format

nums = sorted array of integers

Output Format

new length of array after removal

Constraints

Examples

Example 1:

Input:

nums = [0,0,1,1,1,1,2,3,3]

Output:

7

Explanation:

One possible result is [0,0,1,1,2,3,3], length 7.

Example 2:

Input:

nums = [1,1,1,2,2,3]

Output:

5

Explanation:

Possible result [1,1,2,2,3], length 5.

Example 3:

Input:

nums = [1,2,3]

Output:

3

Explanation:

No duplicates to remove, length remains 3.

Loading...
Remove Duplicates II (Allowed Twice)