class Solution {
public:
int singleNumber(int A[], int n) {
int sum=0,i;
for(i=0;i<n;i=i+1)
{
sum=sum^A[i];
}
return sum;
}
};
Single number (is there any btr solution than this??)

This is the fastest algorithm to solve this problem, with the main "optimizations" being basically cosmetic. However, since you know there is a single number, at the very least, you can do this:
class Solution { public: int singleNumber(int A[], int n) { int sum = A[0], i; for(i=1;i<n;i++) sum ^= A[i]; return sum; } }
The first element is known to exist, so you can start with sum holding it instead of starting with xor of 0 and A[0]. It only saves one bitwise operation, though.

@hebele: That shouldn't work. int r is in the scope of the for loop, which makes it out of scope at the return.