Problem
Problem page: https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/
Topics: Array, Two Pointers
Difficulty: Medium
Follow up for "Remove Duplicates":
What if duplicates are allowed at most twice?For example,
Given sorted array nums =[1,1,1,2,2,3],Your function should return length =
5, with the first five elements of nums being1,1,2,2and3. It doesn't matter what you leave beyond the new length.
Analysis
This is similar to Remove Duplicates from Sorted Array, except that each element can appear up to twice. So we can follow the same approach as in Remove Duplicates from Sorted List II.
Code
1 | class Solution: |
Article link: https://xnerv.wang/en/leetcode-remove-duplicates-from-sorted-array-ii/
