The integer array nums is sorted from smallest to largest. Every value in it appears exactly twice, except for one value that appears only once. Return that value.
Aim for O(log n) time and O(1) extra space. The judge only checks the value you return, so it can't tell how you found it.
2, 5 and 9 each appear twice. 6 appears once.
The lone value can sit at the very start of the array.
It can also sit at the very end.
Constraints
1 <= nums.length <= 10⁵, and nums.length is odd.0 <= nums[i] <= 10⁵nums is sorted in non-decreasing order.Look at where the pairs start. Before the lone value, each pair starts at an even index (nums[0] == nums[1], nums[2] == nums[3], ...). After it, every pair is shifted by one and starts at an odd index.
Because nums is sorted, the two copies of a value always sit side by side. So the array is a row of pairs with one extra element dropped in somewhere.
Time O(log n)Space O(1)
The full walkthrough and code are part of Premium
6