<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:
        '''
        1 1 2 2 3 4 4
              2
        1 1 2 3 3 4 4
              2
        1 1 2 2 3 4 4 8 8
                3

        1 1 2 3 3 4 4 8 8
                3

        3 3 7 7 10 11 11
              3
        3 4 4 7 7 10 10 11 11
                4
        3 3 4 4 7 7 10 10 11
                4
        '''


        def find_single(start, end):
            print(start, end)
            if start >= end:
                return nums[start]
            mid = (end + start) // 2
            even_numbers = (end - mid + 1)%2 == 0
            # if nums[mid] != nums[mid+1] and nums[mid] != nums[mid-1]:
            #     return nums[mid]
            if even_numbers:
                if nums[mid] != nums[mid+1]:
                    return find_single(mid+1, end)
                else:
                    return find_single(start, mid-1)
            else:
                if nums[mid] == nums[mid+1]:
                    return find_single(mid+2, end)
                else:
                    return find_single(start, mid)

            # elif (even_numbers and nums[mid] != nums[mid+1]) or (not even_numbers and nums[mid] == nums[mid+1]):
            #     return find_single(mid+1, end)
            # else:
            #     return find_single(start, mid-1)

        return find_single(0, len(nums)-1)
        
27000