#C8120. Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array
Given a sorted integer array nums
(in non-decreasing order), remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. After removing the duplicates, output the number of unique elements, followed by the unique elements themselves.
You must solve this problem using O(1) extra memory. The input will be provided via standard input (stdin
) and the output should be printed to standard output (stdout
).
For example, given the array [1, 1, 2]
, the output should be 2
on the first line and 1 2
on the second line.
inputFormat
The first line contains an integer n
, denoting the number of elements in the array.
The second line contains n
space-separated integers representing the sorted array nums
.
outputFormat
Output two lines:
1. The first line contains a single integer representing the count of unique elements in the array.
2. The second line contains the unique elements separated by a space.
## sample3
1 1 2
2
1 2
</p>