Find an element in an infinite length sorted array

后端 未结 7 1100
北海茫月
北海茫月 2020-12-13 21:51

Given an infinite length sorted array having both positive and negative integers. Find an element in it.

EDIT
All the elements in the array are

相关标签:
7条回答
  • 2020-12-13 22:38

    Here is another implementation which use 2^n to search occurrence of element itself, and then gives this sub-array to binary search

    e.g.
     arr = 1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1...........
     num = 8;
    
    efficiency = 2logn
    
    0 讨论(0)
提交回复
热议问题