Monday, March 10, 2014

LeetCode: Anagrams && HashMap


Given an array of strings, return all groups of strings that are anagrams.

Note: All inputs will be in lower-case.

Solution:

Use a HashMap to store sorted strings. If two strings are anagrams, they are the same after being sorted.

No comments:

Post a Comment