Remove Duplicates from Sorted Array
Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. Return the number of unique elements.

30:00

Remove Duplicates from Sorted Array
easy
Topics
Companies

Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. Return the number of unique elements.

Example 1:
Input: [1,1,2]
Output: 2
Constraints:
  • 1nums.length3×1041 \leq \text{nums.length} \leq 3 \times 10^4

  • 100nums[i]100-100 \leq \text{nums}[i] \leq 100

  • nums is sorted in non-decreasing order.

Input
arr =[1,1,2]

Two pointer approach

slowfast101122
slow: 0
fast: 1
Unique: 1
Variables
No variables to display
DepthFunction Call
Stack empty
0/3