class Solution {
public int removeDuplicates(int[] nums) {
HashMap<Integer,Integer> win = new HashMap();
int index = 0;
int count = win.getOrDefault(nums[index],0);
win.put(nums[0],++count);
for(int i =1;i<nums.length;i++){
count = win.getOrDefault(nums[i],0);
if (count <3){
win.put(nums[i],++count);
}
if(nums[i] != nums[index] || win.get(nums[i]) <3){
nums[++index] = nums[i];
}
}
return index+1;
}
}
网友评论