[HackerRank][Python3] Sherlock and the Valid String
                2018. 7. 15. 02:33 |
                
                    프로그래밍/HackerRank
                
            
            
            
        Problem :
https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem
My Solution :
#!/usr/bin/env python3
from collections import defaultdict
def isValid(s):
    char_dic, count_dic = defaultdict(int), defaultdict(int)
    for char in s:
        char_dic[char] += 1
    for count in char_dic.values():
        count_dic[count] += 1
    if len(count_dic) == 1:
        return 'YES'
    if len(count_dic) > 2:
        return 'NO'
    m, M = sorted(count_dic)
    if count_dic[1] == 1:
        return 'YES'
    if M - m == 1 and count_dic[M] == 1:
        return 'YES'
    return 'NO'
s = input().strip()
result = isValid(s)
print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Max Min (0) | 2018.07.16 | 
|---|---|
| [HackerRank][Python3] Greedy Florist (0) | 2018.07.16 | 
| [HackerRank][Python3] Luck Balance (0) | 2018.07.15 | 
| [HackerRank][Python3] Common Child (0) | 2018.07.15 | 
| [HackerRank][Python3] Strings: Making Anagrams (0) | 2018.07.15 | 
| [HackerRank][Python3] Count Triplets (0) | 2018.07.13 | 
| [HackerRank][Python3] Frequency Queries (0) | 2018.07.13 | 
| [HackerRank][Python3] Sherlock and Anagrams (0) | 2018.07.12 | 
최근에 달린 댓글 최근에 달린 댓글