A school keeps a sign-in register of roll numbers. The list nums is sorted from small to big, so equal roll numbers sit side by side. Some students signed in many times, but each roll number may stay in the register at most two times.
Clean the register in place. Keep the extra entries out, and keep the order of the remaining ones. Write the kept roll numbers into the first k places of nums, and return k. What lies after the first k places does not matter.
How this judge checks it. It reads two things after your function ends: the number k that you return, and the first k places of nums. Places after the first k are not checked. In the test results the answer is written as [k, [the first k places of nums]]. For example 1 it is [3,[2,2,5]].
Examples
Example 1:
Input: nums = [2,2,2,2,5]
Output: 3, nums = [2,2,5,_,_]
Explanation: Only two of the four 2s stay, and the 5 stays. That makes 3 entries.
Example 2:
Input: nums = [1,1,2,2,2,3,3,3]
Output: 6, nums = [1,1,2,2,3,3,_,_]
Explanation: Each of 1, 2 and 3 stays at most two times, so 6 entries remain.
Example 3:
Input: nums = [6]
Output: 1, nums = [6]
Explanation: A single entry, nothing to remove.