-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsherlock_1.py
More file actions
38 lines (30 loc) · 800 Bytes
/
sherlock_1.py
File metadata and controls
38 lines (30 loc) · 800 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
'''
TestCase를 보고 예외처리함
'''
#!/bin/python3
import math
import os
import random
import re
import sys
from collections import Counter
# Complete the isValid function below.
def isValid(s):
items = Counter(s)
counts = [items[item] for item in items]
if len(set(counts)) > 2:
return 'NO'
if len(set(counts)) == 1:
return 'YES'
if len(set(counts)) == 2:
counts.sort(reverse=True)
if counts[0] != counts[1]:
return 'YES' if counts[0] - counts[1] == 1 else 'NO'
else:
return 'YES' if counts[-1] == 1 and counts[0] == counts[-2] else 'NO'
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = isValid(s)
fptr.write(result + '\n')
fptr.close()