Find the one element that appears exactly once in a sorted array where every other element appears twice.
You are given a sorted integer array in which every value appears exactly twice, except for one value that appears only once.
Return the single value that appears once.
Your solution should run efficiently, taking advantage of the sorted order rather than scanning the array linearly.
nums of length at least 1.nums: a sorted integer arrayExample 1
Input
nums = [1,1,2,3,3,4,4,8,8]
Output
2
Explanation
Every number appears twice except 2, so 2 is the single element.
Example 2
Input
nums = [3,3,7,7,10,11,11]
Output
10
Explanation
All values are paired except 10.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.