跟进“删除重复数字”:
如果可以允许出现两次重复将如何处理?
public class Solution {
/**
* @param A: a array of integers
* @return : return an integer
*/
public int removeDuplicates(int[] nums) {
// write your code here
int re = 0;
for (int i = 0; i < nums.length; ++i) {
int dupsNum = 1;
while (i < nums.length - 1 && nums[i] == nums[i + 1]) {
i++;
dupsNum++;
}
if (dupsNum > 1) {
nums[re] = nums[i];
nums[re + 1] = nums[i];
re += 2;
} else
nums[re++] = nums[i];
}
return re;
}
}