Search in Rotated Sorted Array easy solution
def serach(nums,l,u,target):
if target in nums[l:u+1]:
for i in range(l,u):
if target==nums[i]:
return nums.index(nums[i])
else:
for i in range(u,len(nums)):
if target==nums[i]:
return nums.index(nums[i])
else:
return -1
nums=[4,0,6,7,8,1,2]
l=0
u=(l+len(nums))//2
target=1
print(serach(nums,l,u,target))
output=5
Comments
Post a Comment
If you have any doubt you ask me in comment section