Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #find if there is such element in the list
- #list ISN'T sorted
- n = int(input())
- a = list(map(int, input().split()))
- x = int(input())
- a.sort()
- #we consider elements in positions [l, r) -- a[l], a[l + 1], ..., a[r - 1].
- l = 0
- r = n
- while l < r - 1: #there is more than one element
- m = (l + r) // 2 #look at the value in the middle
- if a[m] <= x:
- l = m
- else:
- r = m
- if a[l] == x:
- print('There is')
- else:
- print ('There isn\'t')
Add Comment
Please, Sign In to add comment