Find the unduplicated element in a sorted array

后端 未结 3 466
情书的邮戳
情书的邮戳 2021-01-18 05:54

Source : Microsoft Interview Question

Given a sorted array, in which every element is present twice except one which is present single time

3条回答
  •  孤独总比滥情好
    2021-01-18 06:32

    Do a binary "search" (rather traversal) on the array, check both neighbors, if both are different from the value in the middle, you have the solution. This is O(log n).

提交回复
热议问题