Leetcode#26. Remove Duplicates from Sorted Array
Problem
Given an integer array nums
sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kept the same. Then return the number of unique elements in nums
.
Consider the number of unique elements of nums
to be k
, to get accepted, you need to do the following things:
- Change the array
nums
such that the firstk
elements ofnums
contain the unique elements in the order they were present innums
initially. The remaining elements ofnums
are not important as well as the size ofnums
. - Return
k
.
Custom Judge:
The judge will test your solution with the following code:
1 | int[] nums = [...]; // Input array |
If all assertions pass, then your solution will be accepted.
Example 1:
1 | Input: nums = [1,1,2] |
Example 2:
1 | Input: nums = [0,0,1,1,1,2,2,3,3,4] |
Constraints:
1 <= nums.length <= 3 * 10^4
100 <= nums[i] <= 100
nums
is sorted in non-decreasing order.
Solve
1 | class Solution: |
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Imisky!
評論