# Python one liner 48ms

• ``````class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
return len([x for x in nums if x<target])``````

• This is `O(n)`, but easy to understand. There is of course binary search with `O(log n)`.

• ``````class Solution(object):
def searchInsert(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
return bisect.bisect_left(nums, target)``````

• @W.G.Jennings
Why don't 0 linear?

``````class Solution(object):
searchInsert = bisect.bisect_left``````

• Brilliant mind! One line beats my nine down to ground...

• interesting!!!

• @W.G.Jennings
So clean, really liked it.

• OG binary search, FYI.

``````def searchInsert(self, nums, target):
low = 0
high = len(nums) - 1
while low <= high:
mid = (low + high) / 2
if nums[mid] == target:
return mid
elif nums[mid] < target:
low = mid + 1
else:
high = mid - 1
return low
``````

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