Group Anagrams
Given a list of strings, return a list of string lists that groups all anagrams together. Two strings are anagrams if rearranging one string results in another. For the purpose of this question, a string is an anagram of itself.
Each group of anagrams should be in alphabetical order. The output should be in alphabetical order by the first elements of each group of anagrams.
Input
strs
: a list of strings.
Output
A list of string lists representing the grouped anagrams.
Examples
Example 1:
Input:
1strs = ["eat" ,"tea", "tan", "ate", "nat", "bat"]
Output: [["ate", "eat", "tea"], ["bat"], ["nat", "tan"]]
Explanation:
Constraints
1 <= len(strs) <= 10^4
1 <= len(strs[i]) <= 100
- Each word in the input consists of lowercase English letters, and they might not be unique.
Try it yourself
Solution
Title
Script
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
Contrary to popular belief, Lorem
Ipsum
is not simply random text.
1 >>> a = [1, 2, 3] 2 >>> a[-1] 3 3