<p>You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.</p>

<p>Return <em>the single element that appears only once</em>.</p>

<p>Your solution must run in <code>O(log n)</code> time and <code>O(1)</code> space.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> nums = [1,1,2,3,3,4,4,8,8]
<strong>Output:</strong> 2
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> nums = [3,3,7,7,10,11,11]
<strong>Output:</strong> 10
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution:
    def singleNonDuplicate(self, nums: List[int]) -> int:
        if len(nums) == 0 or len(nums) == 2 and nums[0] == nums[1]:
            return -1

        if len(nums) == 1:
            return nums[0]

        mid = len(nums) // 2

        left_val = nums[mid - 1]
        mid_val = nums[mid]
        right_val = nums[mid + 1]

        if left_val != mid_val and mid_val != right_val:
            return mid_val
        else:
            left_range = mid
            if left_val == mid_val:
                left_range -= 1
            
            val = self.singleNonDuplicate(nums[:left_range])

            if val != -1:
                return val

            right_range = mid + 1
            if mid_val == right_val:
                right_range += 1

            return self.singleNonDuplicate(nums[right_range:])
25600