You are viewing a single comment's thread. Return to all comments →
while (a[c] != '\0') { first[a[c]-'a']++; c++; }
This can be sped up by trading some space efficiency and using a cache since this part is executed multiple times for the same input.
That solution in Python looks like this:
@functools.lru_cache(100) def get_counts(s): return collections.Counter(s) def check_if_anagrams(one, two): return get_counts(one) == get_counts(two)
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 →
This can be sped up by trading some space efficiency and using a cache since this part is executed multiple times for the same input.
That solution in Python looks like this: