Description
Given an array of strings, group anagrams together.
Example:1
2
3
4
5
6
7Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
Output:
[
["ate","eat","tea"],
["nat","tan"],
["bat"]
]
Note:
- All inputs will be in lowercase.
- The order of your output does not matter.
Idea
You can sort str “ate”,”eat”,”tea” into “aet”, “aet”, “aet”, then they will share the same key, which bring the hashmap into your mind.
Code
1 | class Solution(object): |
Python
1 | # sorted examples |