I solved in C++ using std::map, it took 72 ms.
And i've seen other solutions, is it safe to assume input is always sorted?
I don't think so. You may use bit operator XOR.
It is not sorted, so the fastest way is using XOR. You could refer the following code:
int s = 0;
for (auto it = nums.begin(); it != nums.end(); it++)
s ^= *it;
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.