Remove Duplicates (Two Pointers)

Given a sorted array `nums`, remove the duplicates in-place such that each element appears only once and return the new length of the array.

Input Format

nums = sorted array of integers

Output Format

new length after removing duplicates

Constraints

Examples

Example 1:

Input:

nums = [0,0,1,1,2,2,3,3]

Output:

4

Explanation:

After removal [0,1,2,3], length 4.

Example 2:

Input:

nums = [1,1,2]

Output:

2

Explanation:

After removal [1,2], length 2.

Loading...
Remove Duplicates (Two Pointers) - Two Pointers