Remove Every Duplicated Value
Practice Remove Every Duplicated Value for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
nums is sorted in non-decreasing order. In place, remove every value that appears more than once (all of its copies), keep the values that appear exactly once in their original order at the front, and return k, how many were kept.
The test checks both k and the first k elements of nums, written as [k, nums[:k]].
Example
nums = [1,2,2,3,3,3,4] -> [2, [1,4]]
Constraints
- 1 <= nums.length <= 3 * 10^4
numsis sorted in non-decreasing order
Similar to LC 82 (Remove Duplicates from Sorted List II), on an array instead of a list.