Reputation: 1
class Solution:
def search(self, nums: List[int], target: int) -> int:
#establish a left and right limit
l = 0
#this will take from the right and push more towards the middle to // by 2
r = len(nums) - 1
#create the mid
m = (l + r) // 2
#move the mid more towards the right
if nums[m] > target:
r = m - 1
elif nums[m] < target:
l = m + 1
else:
print("-1")
#im calling the function even when i removed the type error I dont think its counting the array and i dont know why
search(0, len(nums = [-1,0,3,5,9,12]), 9)
#error code: TypeError: len() takes no keyword arguments
^^^^^^^^^^^^^^^^^^^^^^^^^^^
# search(0, len(nums = [-1,0,3,5,9,12]), 9)
#Line 22 in <module> (Solution.py)
I was hoping that calling the function would run the binary search, but calling the function isnt working even when i removed the type error
Upvotes: 0
Views: 23