Sunday, May 22, 2016

Anagram

From cracking the coding interview.

What's the easiest way of checking if two words are anagrams?

We could count the occurrences of the distinct characters in each string and return true if they match. Or,
we could just sort the string. After all, two words which are anagrams will look the same
once they're sorted.

No comments: