Here is the algorithm:

First sort the input.

Then check whether element at position i , i + 1 , and i+2 are the same or not.

If the three elements are the same , then add two to the loop counter , if they are not the same then element at position i is the missing one return it.

What happens if the missing element is at position nums.length-1 e.g. [1,1,1,2,2,2,3,3,3,4,4,4,5] ?

to handle this case we need to return nums[nums.length-1] at the end.

```
public int singleNumber(int[] nums) {
Arrays.sort(nums);
if(nums.length == 0 ) return 0;
for(int i = 0; i < nums.length-2; i++ ){
if(nums[i] != nums[i+1] || nums[i] != nums[i+2]){
return nums[i];
}else{
i += 2;;
}
}
return nums[nums.length-1];
}
```