Removing duplicates from a sorted array
Swift
Medium
arrays
Task «Removing duplicates from a sorted array»
Given a non-decreasing sorted array of integers, you need to remove all duplicates so that each element appears at most twice. The changes must be made in place, i.e., in the original array. Return the new length of the array after removing extra elements. The remainder of the array after the new length may contain any values.
Input Format
First line: an integer n (1 ≤ n ≤ 10^5) — the number of elements. Second line: n integers separated by spaces.
Output Format
One integer — the new length of the array.
Examples
Example 1
INPUT
5
0 0 1 1 2
OUTPUT
5
main.swift