solution – hashtable
# time O(N) space O(1)
solution2 -binary
# time O(lgN) space O(1)
def isMajority(nums,target):
def bs(nums,t):
l = 0
r = len(nums)-1
while nums[l] < nums[r]:
mid = (l+r) >>1
if nums[mid] < target:
l = mid+1
else:
r = mid
return l
first_idx = bs(nums,5)
last_idx = bs(nums,5) + len(nums)//2
return last_idx < len(nums) and nums[last_idx] == target