```
public class Solution {
public int removeDuplicates(int[] nums) {
int [] a = new int [1000];
int [] b = new int [1000];
int j = 0;
for(int i = 0; i < nums.length; i++){
if(nums[i] >= 0){
if(a[nums[i]]< 2){
a[nums[i]]++;
nums[j] = nums[i];
j++;
}
}else{
int tmp = -nums[i];
if(b[tmp] < 2){
b[tmp]++;
nums[j] = nums[i];
j++;
}
}
}
return j;
}
}
```