This repository contains a Java program that solves the "Remove Duplicates from Sorted Array" problem. Given an integer array nums sorted in non-decreasing order, the program removes the duplicates in-place such that each unique element appears only once. The relative order of the elements is kept the same. The program then returns the number of unique elements in nums.
To be accepted, the program needs to fulfill the following requirements:
- Change the array
numssuch that the firstkelements ofnumscontain the unique elements in the order they were present innumsinitially. The remaining elements ofnumsare not important, as well as the size ofnums. - Return
k.
A custom judge is used to test the solution with the provided input array and the expected answer. If all assertions pass, the solution will be accepted.
nums = [1,1,2]
2, nums = [1,2,_]
Explanation: The function should return k = 2, with the first two elements of nums being 1 and 2, respectively. It does not matter what is left beyond the returned k (hence they are represented as underscores).
- 1 <=
nums.length<= 3 * 10^4 - -100 <=
nums[i]<= 100 numsis sorted in non-decreasing order.