Very Simple (Easy to Understand) 0ms , c++ soln
\n\n# Approach\n\n    Let There be 2 arrays .\n    a1 = [1,1,2,2,3,3,4,4]; -> point 1\n    a2  = [1,1,2,2,3,3]; -> point 2\n\n    here , let start = 0 , end = a
\n\n# Approach\n\n    Let There be 2 arrays .\n    a1 = [1,1,2,2,3,3,4,4]; -> point 1\n    a2  = [1,1,2,2,3,3]; -> point 2\n\n    here , let start = 0 , end = arr.size() -1;\n\n    a1 has even no of pairs  = 4 , s = 0 , e = 7;\n    a2 has odd no of pairs  = 3 , s = 0, e = 5;\n\n    Let us assume 1 element added to the 2 arrays .\n    now,\n    for a1 -> s = 0, e = 8; pairs = (s-e)/2 = 4;\n    for a2 -> s = 0 , e = 6; pairs = (s-e)/2 = 3;\n\n    now when you find mid for both the arrays ;\n    m = (s+e)/2;\n    for a1; \n        m = (0+8)/2 = 4;\n        from point 1 you can see that nums[m] = 3 and nums[m+1] also 3;\n        This means , \n        if we get nums[m]=nums[m+1] then element to be found will be on right\n        if not this means the a1 in point1 is shifted by 1 space which is present on left of m;\n    \n\n    for a2; \n        m = (0+6)/2 = 3;\n        from point 1 you can see that nums[m] = 2 and nums[m-1] also 2;\n        This means , \n        if we get nums[m]=nums[m-1] then element to be found will be on right\n        if not this means the a1 in point1 is shifted by 1 space which is present on left of m;\n\n    PLEASE UPVOTE;\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int singleNonDuplicate(vector<int>& nums) {\n        int n = nums.size() ,s = 0, e = n-1;// x  =  number of pairs excluding single element\n        if(n==1 || nums[0]!=nums[1]) // if nums have single element or first element is the answer\n            return nums[0];\n        if(nums[n-2]!=nums[n-1]) // if last element is the answer\n            return nums[n-1];\n        while(s<=e){\n            int m = (s+e)/2 , x = (s-e)/2;\n            if(nums[m]!=nums[m+1] && nums[m]!=nums[m-1])\n                return nums[m];\n            if(x%2==0) // even number of pairs\n            {\n                if(nums[m-1]==nums[m]) // move left\n                    e=m-2;\n                else // move right\n                    s=m+2;\n            }\n            else // odd number of pairs \n            {\n                if(nums[m-1]==nums[m]) // move right\n                    s=m+1;\n                else // move left\n                    e=m-1;\n            }\n        }\n        return -1; // PLEASE UPVOTE \uD83E\uDD7A\n    }\n};\n```
['C++']