Easy C++ O(log n) & O(1) soln.
for (mid % 2 == 0) cases              \n    0 1 2 3 4 5 6 7 8 -> index             \n    1 1 2 2 3 5 5 7 7 - ON MID        \n\t1 1 3 5 5 7 7 9 9 - ON LEFT      
for (mid % 2 == 0) cases              \n    0 1 2 3 4 5 6 7 8 -> index             \n    1 1 2 2 **3** 5 5 7 7 - ON MID        \n\t1 1 **3** 5 5 7 7 9 9 - ON LEFT       \n\t1 1 2 2 3 3 **5** 7 7 - ON RIGHT    \n\t\nFor (mid % 2 != 0) cases \n0 1 2 3 4 5 6 -> index\n1 1 2 2 **3** 5 5 - ON RIGHT\n1 1 **3** 5 5 7 7 - ON LEFT\n\n\n```\nint singleNonDuplicate(vector<int>& v) \n    {\n        if(v.size() == 1)// if only one element is present\n            return v[0];\n        int low = 0;\n        int high = v.size() - 1;\n        while(low <= high)\n        {\n            int mid = low + (high - low) / 2;\n            if(mid % 2 == 0)\n            {\n                if(low == high) //if element is on the left most side , in that case, v[mid - 1] is not possible\n                {    \n                    return v[mid];\n                }\n                else if(v[mid] == v[mid - 1])\n                {\n                    high = mid - 2;\n                }\n                else if(v[mid] == v[mid + 1])\n                {\n                    low = mid + 2;\n                }\n                else\n                {\n                    return v[mid];\n                }\n            }\n            else\n            {\n                if(v[mid] == v[mid - 1])\n                {\n                    low = mid + 1;\n                }\n                else if(v[mid] == v[mid + 1])\n                {\n                    high = mid - 1;\n                }\n            }\n        }\n        return 0;\n    }\n```
[]