You are viewing a single comment's thread. Return to all comments →
My solution is very similar to yours. I just want to include it here for reference:
def sherlockAndAnagrams(s): anagram_dict = {} count = 0 for i in range(1, len(s)): for j in range(len(s)-i+1): current_sorted = str(sorted(s[j:j+i])) if (current_sorted not in anagram_dict): anagram_dict[current_sorted] = 1 else: count += anagram_dict[current_sorted] anagram_dict[current_sorted] += 1 return count
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Anagrams
You are viewing a single comment's thread. Return to all comments →
My solution is very similar to yours. I just want to include it here for reference: