The kind of problem when you have no idea, it is very difficult. But once you know how to make it, it is very simple. Just use the XOR operation and go over the array. The numbers show up twice will disappear eventually.
public class Solution {
public int singleNumber(int[] A) {
int ans = A[0];
for(int i=1;i<A.length;i++)
{
ans ^= A[i];
}
return ans;
}
}