```
public class Solution {
public int removeElement(int[] A, int elem) {
if(A.length == 0) return 0;
HashSet<Integer> uniqElems = new HashSet<>();
for(int i = 0; i < A.length; i++) {
if(!uniqElems.contains(A[i])) {
uniqElems.add(A[i]);
}
}
Iterator<Integer> itr = uniqElems.iterator();
int j = 0;
while(itr.hasNext()) {
A[j++] = (Integer)itr.next().intValue();
}
return j + 1;
}
}
```