Remove Duplicated
Last updated
Last updated
public class Solution {
/*
* @param nums: an array of integers
* @return: the number of unique integers
*/
public int deduplication(int[] nums) {
// write your code here
/*
[1, 2, 3, 4, 3, 4, 4]
l
r
*/
if (nums == null || nums.length == 0) {
return 0;
}
Arrays.sort(nums);
int l = 0, r = 0;
while (r < nums.length) {
if (nums[r] != nums[l]) {
l++;
nums[l] = nums[r];
}
r++;
}
return l + 1;
}
}