Short, compare nums[i] with nums[i^1]
Simply find the first index whose "partner index" (the index xor 1) holds a different value.\n\nRuby:\n\ndef single_non_duplicate(nums)\n  nums[(0..nums.size).b
Simply find the first index whose "partner index" (the index xor 1) holds a different value.\n\n**Ruby:**\n```\ndef single_non_duplicate(nums)\n  nums[(0..nums.size).bsearch { |i| nums[i] != nums[i^1] }]\nend\n```\n**Python**\n\n    def singleNonDuplicate(self, nums):\n        lo, hi = 0, len(nums) - 1\n        while lo < hi:\n            mid = (lo + hi) / 2\n            if nums[mid] == nums[mid ^ 1]:\n                lo = mid + 1\n            else:\n                hi = mid\n        return nums[lo]\n\n**Java:**\n\n    public int singleNonDuplicate(int[] nums) {\n        int lo = 0, hi = nums.length - 1;\n        while (lo < hi) {\n            int mid = (lo + hi) >>> 1;\n            if (nums[mid] == nums[mid ^ 1])\n                lo = mid + 1;\n            else\n                hi = mid;\n        }\n        return nums[lo];\n    }
[]