Beats 91.47%||C++||Binary Search||Easy
Complexity\n- Time complexity:\nO(logn)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n//index of form:(even,odd) before pivot and of form
# Complexity\n- Time complexity:\nO(logn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n//index of form:(even,odd) before pivot and of form (odd,even) after pivot for equal elements\n    int singleNonDuplicate(vector<int>&nums) \n    {\n        int left=0,right=nums.size()-1;\n        while(left<=right)\n        {\n            int mid=(left+right)/2;\n            if(left==right)\n            {\n                return nums[mid];\n            }\n            if(mid==0 && nums[mid+1]!=nums[mid])\n            {\n                return nums[mid];\n            }\n            if(nums[mid+1]!=nums[mid] && nums[mid-1]!=nums[mid])\n            {\n                return nums[mid];\n            }\n            else if((nums[mid+1]==nums[mid] && mid%2==1)||(nums[mid-1]==nums[mid] && mid%2==0))\n            {\n                right=mid-1;\n            }\n            else if((nums[mid+1]==nums[mid] && mid%2==0)||(nums[mid-1]==nums[mid] && mid%2==1))\n            {\n                left=mid+1;\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']