-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSherlock.py
More file actions
39 lines (35 loc) · 889 Bytes
/
Sherlock.py
File metadata and controls
39 lines (35 loc) · 889 Bytes
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
37
38
39
def calc(s):
alphaDict = dict.fromkeys(s, 0)
for i in s:
alphaDict[i] += 1
track={}
alphaDict2=dict(alphaDict)
for key,value in alphaDict.items():
if value not in track:
track[value]=0
else:
track[value]+=1
freq = (max(track, key=track.get))
print(freq)
count=0
for key,value in alphaDict.items():
if value==freq and count<2:
continue
elif (value-1)==freq and count<2:
count+=1
elif count<1:
count+=1
alphaDict[key]-=1
if alphaDict[key]==0:
del alphaDict2[key]
else:
continue
else:
return 'NO'
for value in alphaDict2.values():
if value==freq:
return 'YES'
else:
return 'NO'
s = "aaaabbcc"
print(calc(s))