solutions in Python


  • 0
    G

    import math
    def searchInsertPosition(lst,value):
    start=0
    end=len(lst)-1
    middle=math.floor((start+end)/2)
    if value<lst[0]:
    return 0
    if value>lst[-1]:
    return len(lst)
    while middle>start:
    if lst[middle]==value:
    return middle
    elif lst[middle]>value:
    end=middle
    else:
    start=middle
    middle=math.floor((start+end)/2)
    else:
    return middle+1

    searchInsertPosition([1,3,5,6],0)


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.