Java | C++ | Python3 | Easy explanation | O(logn) | O(1)
\nEXPLANATION:-\nSuppose array is [1, 1, 2, 2, 3, 3, 4, 5, 5]\nwe can observe that for each pair, \nfirst element takes even position and second element takes o
```\nEXPLANATION:-\nSuppose array is [1, 1, 2, 2, 3, 3, 4, 5, 5]\nwe can observe that for each pair, \nfirst element takes even position and second element takes odd position\nfor example, 1 is appeared as a pair,\nso it takes 0 and 1 positions. similarly for all the pairs also.\n\nthis pattern will be missed when single element is appeared in the array.\n\nFrom these points, we can implement algorithm.\n1. Take left and right pointers . \n    left points to start of list. right points to end of the list.\n2. find mid.\n    if mid is even, then it\'s duplicate should be in next index.\n\tor if mid is odd, then it\'s duplicate  should be in previous index.\n\tcheck these two conditions, \n\tif any of the conditions is satisfied,\n\tthen pattern is not missed, \n\tso check in next half of the array. i.e, left = mid + 1\n\tif condition is not satisfied, then the pattern is missed.\n\tso, single number must be before mid.\n\tso, update end to mid.\n3. At last return the nums[left]\n\nTime: -  O(logN)\nspace:-  O(1)\n\n\nIF YOU  HAVE ANY DOUBTS, FEEL FREE TO ASK\nIF YOU UNDERSTAND, DON\'T FORGET TO UPVOTE.\n```\n```\nJava:-\nclass Solution {\n    public int singleNonDuplicate(int[] nums) {\n        int left = 0, right = nums.length-1;\n        while(left < right){\n            int mid = (left + right)/2;\n            if( (mid % 2 == 0 && nums[mid] == nums[mid +1]) || (mid %2 == 1 && nums[mid] == nums[mid - 1]) )\n                left = mid + 1;\n            else\n                right = mid;\n        }\n        return nums[left];\n    }   \n}\n\nPython3:-\nclass Solution:\n    def singleNonDuplicate(self, nums: List[int]) -> int:\n        left, right = 0, len(nums)-1\n        while left < right:\n            mid = int((left + right)/2)\n            if (mid % 2 == 1 and nums[mid - 1] == nums[mid]) or (mid%2 == 0 and nums[mid] == nums[mid + 1]):\n                left = mid + 1\n            else:\n                right = mid\n        return nums[left]\n\t\t\nC++:-\nclass Solution {\npublic:\n    int singleNonDuplicate(vector<int>& nums) {\n        int left = 0, right = nums.size() - 1;\n        while(left < right){\n            int mid = (left + right)/2;\n            if((mid % 2 == 0 && nums[mid] == nums[mid + 1]) || (mid % 2 == 1 && nums[mid] == nums[mid - 1]))\n                left = mid + 1;\n            else\n                right = mid;\n        }\n        \n        return nums[left];\n    }\n};\n```\n\n\nI have started a series on solid principles and design patterns. If anyone is interested, please check [it](https://medium.com/@bhanu150138/mastering-solid-principles-and-design-patterns-a-blog-series-for-writing-clean-scalable-code-aae3809310db) out.
['C++', 'Java', 'Python3']