C++ Simple and Clean Solutions, O(logn), With Explanation
O(logn) Binary Search Solution:\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an 
**O(logn) Binary Search Solution:**\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an odd index.\nIf somewhere in the middle we have an element that appears only once, this pattern will be broken, and from there on the first element will be in an odd index and the second one in an even index.\nSo, we makr a regular binary search. If the pattern is still holding in "mid", then we continue searching in the right side.\nIf it\'s already broken, we continue the search on the left side.\n```\nclass Solution {\npublic:\n    int singleNonDuplicate(vector<int>& nums) {\n        int lo = 0, hi = nums.size()-1, mid;\n        while (lo < hi) {\n            mid = (lo + hi) / 2;\n            if ((mid % 2 && nums[mid - 1] == nums[mid]) || (!(mid % 2) && nums[mid] == nums[mid + 1])) lo = mid + 1;\n            else hi = mid;\n        }\n        return nums[lo];\n    }\n};\n```\n**O(n) Bitwise Solution:**\nA number XOR itself is always 0.\nA number XOR 0 always stays the number.\nSo if we just XOR the entire array, we will be left with the element that appears only once.\n```\nclass Solution {\npublic:\n    int singleNonDuplicate(vector<int>& nums) {\n        int res = nums[0];\n        for (int i=1; i<nums.size(); i++)\n            res ^= nums[i];\n        return res;\n    }\n};\n```\n**Like it? please upvote!**
['C']