Search⌘ K
AI Features

Solution: Remove Duplicates from Sorted Array

Understand how to use the two-pointer technique to remove duplicates from a sorted array without additional space. This lesson teaches you to modify the array in-place, maintaining sorted order and achieving linear time complexity, by scanning and shifting unique elements as needed.

Statement

You are given an integer array nums that is already sorted in non-decreasing order. Your task is to remove the duplicate values in-place so that each element in the array appears only once, while preserving the original relative order of the elements.

After removing the duplicates, let k be the number of unique elements remaining in the array. The first k ...