C++ Solution O(logn) with detailed explanation
\nWe use binary search to solve this.\n\nThe problem of using binary search is how to determine the conditions inside the while loop?\n\nWell this logic maynot 
```\nWe use binary search to solve this.\n\nThe problem of using binary search is how to determine the conditions inside the while loop?\n\nWell this logic maynot come that intuitively but if u observe a few examples u will quickly get the idea.\n\nLet num=[1,1,2,3,3,4,4,8,8]\n         0,1,2,3,4,5,6,7,8 <----indices\n\nLet us do our traditional binary search start and see what happens:-\nl=0,r=nums.size()-1=8\nm=4\n\n[1,1,2,3,3,4,4,8,8]\n         ^\n         |\n         mid\nNotice that once we hit the mid and remove its duplicate(if it doesnt have any that would be the answer)-> the answer will lie in the subarray \nconstaining odd length (cuz everything will be paired up except for 1 thus odd length)\n\n[1,1,2, ,4,4,8,8]\n\\_____/  \\______/\n   |         |\n odd        even \n length     length\n\n Thus our answer is present in the odd length of the array.\n\n But one problem here  is how to find after the split whether its odd and even by making sure we stick to the complexity of o(logn).\n\n U initialize a bool variable and check if the r-mid is even or not.\n[1,1,2,3,3,4,4,8,8]\nFor this example 8-4=4 is even that mean ur answer cant lie in the right side of the array.\nSo we can test our solution like this\n\nbool even_length=(r-m)%2==0\nif(nums[m]==nums[m-1])\n{\n\tif(even_length)\n\t\tr=m-2;\n\telse \n\t\tl=m+1;\n}\n\ndid u understand? ->I am writing the code to suit for the above example \n\nNow what if nums[m]==nums[m+1]\nnums=[1,1,4,4,5,5,6,7,7]\n              ^\n              |\n              mid \nHere r-m=even but wait...\nm+1 has to be removed too \nthus eventhough the right side show even due to the above property it has to odd cuz we subtract 1 element\nThen just follow the same procedure\n\nif(nums[m]==nums[m+1])\n{\n\tif(even_length)\n\t\tl=m+2;\n\telse\n\t\tr=m-1;\n}\n\n\nCode:-\n\n    int singleNonDuplicate(vector<int>& nums) {\n        int l=0,r=nums.size()-1;\n        while(l<r)\n        {\n            int m=l+(r-l)/2;\n            bool even_length=(r-m)%2==0;\n            if(nums[m]==nums[m+1])\n            {\n                if(even_length)\n                    l=m+2;\n                else\n                r=m-1;\n            }\n            else if(nums[m]==nums[m-1])\n            {\n                if(even_length)\n                    r=m-2;\n                else\n                    l=m+1;\n            }\n            else\n                return nums[m];\n        }\n        return nums[l];\n    }\n\n\n\n```
['C', 'C++']