Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You must write an algorithm with O(log n)
runtime complexity.
Solution:
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
for i in range(len(nums)):
if(nums[i]>=target):
return i
return len(nums)
Good post. I learn something totally new and challenging on websites I stumbleupon on a daily basis. It will always be useful to read articles from other writers and practice something from other web sites.
Top site ,.. amazaing post ! Just keep the work on !