Given an array of integers, every element appearstwiceexcept for one. Find that single one.
Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
struct OP { int operator() (int x, int y) { i*=-1; return x+i*y; } OP():i(-1){}; int i; }; class Solution { public: int singleNumber(vector& nums) { sort(nums.begin(), nums.end()); return accumulate(nums.begin(), nums.end(), 0, OP()); } };