Remove Duplicates from Sorted Array

Given a sorted array `nums`, remove the duplicates in-place such that each element appears only once. Return the new length after removal.

Input Format

nums = sorted array of integers

Output Format

new length of array after removing duplicates

Constraints

Examples

Example 1:

Input:

nums = [1,1,2]

Output:

2

Explanation:

Remove duplicates [1,1] -> [1], new length is 2 (array [1,2]).

Example 2:

Input:

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

Output:

5

Explanation:

Result array [0,1,2,3,4], length 5.

Loading...
Remove Duplicates from Sorted Array