Swift | Binary Search | 6 SLOC
\u26A0\uFE0F - Solution is supposed to be O(log n)/O(1). Seeing many Swift posted solutions that are O(n)/O(n).\n\n---\nBinary Search (accepted answer)\n\nclass
\u26A0\uFE0F - Solution is supposed to be O(log n)/O(1). Seeing many Swift posted solutions that are O(n)/O(n).\n\n---\n**Binary Search (accepted answer)**\n```\nclass Solution {\n    func singleNonDuplicate(_ nums: [Int]) -> Int {\n        var (left, right) = (0, nums.count-1)\n        while left < right {\n            let mid = (left+right)/2\n            (left, right) = nums[mid & ~1] == nums[mid & ~1+1] ? (mid+1, right) : (left, mid)\n        }\n        return nums[left]\n    }\n}\n```\n\n---\n\n**SEE ALSO:** [A One-Liner Solution](https://leetcode.com/problems/single-element-in-a-sorted-array/discuss/3212093/Swift-or-One-Liner)
['Swift']