✅Python3 two approaches 🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nUsing xor approach and binary search we can solve this.\n\n# Approach 1: XOR 170ms\n De
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using xor approach and binary search we can solve this.**\n\n# Approach 1: XOR 170ms\n<!-- Describe your approach to solving the problem. -->\n- traverse in array linearly and xor every element.\n- which ever element is not repeted it\'s xor will not be canclled out.\n- return found xor.\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def singleNonDuplicate(self, nums: List[int]) -> int:\n        def helper():\n            xor = 0\n            for i in nums:\n                xor ^= i\n            return xor\n        return helper()\n```\n---\n\n# Approach 2: Binary search 180ms\n<!-- Describe your approach to solving the problem. -->\n- here if we explore problem then we can see if we have even length of array then no element will be singlton and every even index will have next element same as it.\n- but if we insert any simgleton element between repeted element(not in between pair) then we can see that if even index element is not having same element as next then singleton must be in left side.\n- if that\'s not the case then singleton is not inserted in left side because we\'re having behavior like even length array and no singleton is present in it, so to search in left side is not in our favour.\n- so singleton must be in right side.\n- where we find right < left there, we stop.\n- return nums[left].\n\n# Complexity\n- Time complexity: O(logN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def singleNonDuplicate(self, nums: List[int]) -> int:\n        def helper():\n            left, right = 0, len(nums) - 1\n            while left < right:\n                middle = (left + right) // 2\n                if middle % 2 == 1:\n                    middle -= 1\n                if nums[middle] != nums[middle+1]:\n                    right = middle - 1\n                else:\n                    left = middle + 2\n            return nums[left]\n        return helper()\n```\n---\n# Please like and comment below.\n# (\uD83D\uDC4D\u2256\u203F\u203F\u2256)\uD83D\uDC4D \uD83D\uDC4D(\u2256\u203F\u203F\u2256\uD83D\uDC4D)
['Array', 'Binary Search', 'Python3']