✔️ Straightforward Approach Using Binary Search, With Comments
Thumbs up if you find this helpful \uD83D\uDC4D\n\nThe idea of this solution is the following:\n\nSuppose we have the following array: [1,1,2,2,3,3,4,4,6,8,8]\n
**Thumbs up if you find this helpful** \uD83D\uDC4D\n\nThe idea of this solution is the following:\n\nSuppose we have the following array: ```[1,1,2,2,3,3,4,4,6,8,8]```\n\nWe can observe that for each pair: \n\n* The first pair element takes the even array index position \n* The second pair element takes the odd array index position\n\nFor example, when examining the number 1 as a pair, we see it takes the array index positions ```0``` and ```1```. \n\nSimilarly for all other pairs, the first pair element takes the even array index position, and the second pair element takes the odd array index position.\n\nUsing this idea, we can see that this pattern for pairs will break when a single element appears in the array.\n\nIn this solution, we use binary search to look for the point in the array where the pattern mentioned above for the pairs first breaks.\n\n```\npublic class Solution {\n    public int SingleNonDuplicate(int[] nums) {    \n        var lo = 0;\n        var hi = nums.Length - 1;\n        \n        while (lo < hi) {\n            // Get the mipoint\n            var mid = lo + (hi - lo) / 2;\n            \n            // Check to see if mid is even\n            var isEven = mid % 2 == 0;\n            \n            // If mid is even, its duplicate should be the next index\n            // If mid is odd, its duplicate should be the previous index\n            if ((isEven && nums[mid] == nums[mid + 1]) || (!isEven && nums[mid] == nums[mid - 1])) {\n                // Duplicate found, advance to next index. Single element is > mid\n                lo = mid + 1;\n            } else {\n                // Pattern is broken. Single element is <= mid\n                hi = mid;\n            }           \n        }        \n        return nums[lo];\n    }\n}\n```
[]