https://www.hackerrank.com/interview/interview-preparation-kit/strings/challenges
아.. 또 노가다로 푼거 같다.
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the isValid function below.
def isValid(s):
diff = {}
for i in s:
if i not in diff:
diff[i] = 1
else:
diff[i] += 1
print(diff)
a = sorted([i for i in diff.values()])
l = len(a)
if a[0] == a[l-1]:
return "YES"
elif a[0] != a[1] and a[l-1] == a[l-2]:
if a[0] == 1:
return "YES"
else:
return "NO"
elif a[0] == a[1] and a[l-1] != a[l-2]:
if a[l-1]-1 == a[l-2]:
return "YES"
else:
return "NO"
return "NO"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
s = input()
result = isValid(s)
fptr.write(result + '\n')
fptr.close()
'algorithm > python' 카테고리의 다른 글
hackerrank/Stacks and Queues/Balanced Brackets (0) | 2020.03.09 |
---|---|
hackerrank/Hash Tables/Ransom Note (0) | 2020.03.09 |
프로그래머스/완전탐색/모의고사 (0) | 2020.03.08 |
프로그래머스/힙/더 맵게 (0) | 2020.03.07 |
프로그래머스/스택,큐/탑 (0) | 2020.03.07 |