-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
36 lines (30 loc) · 844 Bytes
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def areValidLetters(letters):
for letter in letters:
if len(letter) != 1 and (letter not in 'qwertyuiopasdfghjklzxcvbnm'):
return False
return True
def areValidLocations(spaces):
for space in spaces:
try:
location = int(space)
except ValueError:
return False
return True
def binarySearch(target, elements):
left = 0
right = len(elements)
if right == 0:
return False
middle = 1
while (left + 1 != right):
middle = (left + right + 1) // 2
if target < elements[middle]:
right = middle
elif target > elements[middle]:
left = middle
else:
return True
if target == elements[left]:
return True
else:
return False