Single Element in a Sorted Array

|2021-2-1
AlphaBoom
AlphaBoom
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. Find this single element that appears only once.
Follow up: Your solution should run in O(log n) time and O(1) space.
  1. 不需要的数时成对的,所以可以通过xor操作将他们置为0,最后的数就是结果
    1. 答案要求是时间复杂度为log n,由于是已经排序的数组那么,可以考虑使用二分查找,根据奇偶来判断在哪边查询
      Loading...