You are viewing a single comment's thread. Return to all comments →
Python 3:
def sherlockAndAnagrams(s): n = len(s) out = 0 hash_map = defaultdict(lambda:0) for i in range(n): for j in range(i+1, n+1): c = "".join(sorted(s[i:j])) out += hash_map[c] hash_map[c] += 1 return out
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 →
Python 3: