Remove Duplicates Occurring More Than Twice
Given a list of integers nums
sorted in ascending order, remove in-place duplicates that appear more than twice.
This should be done in \(\mathcal{O}(1)\) space.
Constraints
n ≤ 100,000
wheren
is the length ofnums
https://binarysearch.com/problems/Remove-Duplicates-Occurring-More-Than-Twice
Examples
Example 1
Input
- nums =
[1, 1]
Output
- answer =
[1, 1]
Example 2
Input
- nums =
[3, 3, 3, 3, 4, 4, 8]
Output
- answer =
[3, 3, 4, 4, 8]
Explanation
We remove the third and fourth 3
since they occur more than twice.
Leave a comment