Skip to main content
Post Closed as "Not suitable for this site" by Martin R, Juho, pacmaninbw
Add "complexity" tag
Link
JimmyHu
  • 7.6k
  • 2
  • 11
  • 48
Became Hot Network Question
Source Link
111
  • 53
  • 3

Binary Search written in python with O(n)

def search(nums, target):
    for i in range(len(nums)):
        if nums[i] == target:
            return i
        if nums[i] == None:
          return -1

I think this code will be good for most cases in binary search but in some cases might need a better version of the code that is O(log n).