[HackerRank][Python3] Sherlock and Anagrams
2018. 7. 12. 22:14 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem
My Solution :
#!/usr/bin/env python3 def sherlockAndAnagrams(s): total = 0 chunk_dic = {} for i in range(1, len(s)): for j in range(len(s)-i+1): chunk = ''.join(sorted(s[j:j+i])) total += chunk_dic.setdefault(chunk, 0) chunk_dic[chunk] += 1 return total q = int(input()) for _ in range(q): s = input() result = sherlockAndAnagrams(s) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Sherlock and the Valid String (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] Array Manipulation (0) | 2018.07.09 |
[HackerRank][Python3] New Year Chaos (0) | 2018.07.07 |
[HackerRank][Python3] Minimum Swaps 2 (0) | 2018.07.06 |
[HackerRank][Python3] Is This a Binary Search Tree? (2) | 2018.06.25 |
최근에 달린 댓글 최근에 달린 댓글