Leetcode 80: Remove Duplicates from Sorted Array II
1 min readApr 23, 2024
This is a variant on Remove Duplicates from Sorted Array which for which I put a solution in this link.
This exercise is very similar to Remove Duplicates from Sorted Array (I), but this time duplicates are allowed, and elements can occur at most 2 times.
a. Update to the simple remove duplicates algorithm
We can simply follow the same pattern as in the previous exercise, but instead of comparing nums[i-1] and nums[i], we compare nums[i-2], nums[i-1] and…