Single Element in a Sorted Array

You are given a non-empty integer array nums sorted in ascending order. Exactly one value appears once, and every other value appears exactly twice. Return…

You are given a non-empty integer array `nums` sorted in ascending order. Exactly one value appears once, and every other value appears exactly twice. Return the value that appears once. Your optimal solution should run in `O(log n)` time and use `O(1)` extra space.

- `1 <= nums.length <= 10^5` - `nums.length` is odd. - `-10^5 <= nums[i] <= 10^5` - `nums` is sorted; one value occurs once and every other value occurs twice.

Example 1: input nums = [1,1,2,3,3,4,4]; output 2. Every value except 2 has an adjacent equal partner.

Example 2: input nums = [1,1,3,5,5]; output 3. The pair alignment breaks at 3.

Category: Binary Search. Topic: binary-search. Difficulty: Medium. Patterns: binary-search.