Binary Search Easy Left and Right Half Approach
Intuition\ncheck for left half and right half\n\n# Approach\nobservation->in left half odd index->2nd occurance of some no\neven index->1st occurance of no\nin 
# Intuition\ncheck for left half and right half\n\n# Approach\nobservation->in left half odd index->2nd occurance of some no\neven index->1st occurance of no\nin right half\nodd index ->first occurance of no\neven index->second occurance\naccording reduce search space by applying mid+1 or mid-1 for \nperticular conditions\nIF (YOU UNDERSTOOD THIS SOLUTION){UPVOTE}\nELSE {CHECK CODE AND THEN UPVOTE}\n\n# Complexity\n- Time complexity:\no(log(n))\n\n- Space complexity:\no(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int singleNonDuplicate(vector<int>& nums) {\n        int s=0;\n        int e=nums.size()-2;\n        int mid=s+(e-s)/2;\n        while(s<=e)\n        {\n\n            if((mid&1)==0)\n                {if(nums[mid]==nums[mid+1])\n                {\n                    s=mid+1;\n                }\n                else{\n                    e=mid-1;\n                }\n            }\n            else{\n                if(nums[mid]==nums[mid+1])\n                {\n                    e=mid-1;\n                }\n                else\n                {\n                    s=mid+1;\n                }\n            }\n            mid=s+(e-s)/2;\n\n        }\n         return nums[mid];\n    }\n};\n```
['C++']