← 返回 databricks 的题目列表Group Anagrams
类型:online_judge
Given an array of strings strs, group the strings that are anagrams of one another. The order of groups and the order of strings within a group do not matter.
Two strings are anagrams if and only if they contain exactly the same characters with the same frequencies.
Input format
First line: an integer n, the number of strings.
Second line: n space-separated strings consisting of lowercase English letters.
Output format
Print one group per line, with strings in a group separated by spaces. The output order is arbitrary.
Example
Input:
6
eat tea tan ate nat bat
One valid output:
eat tea ate
tan nat
bat
Constraints
1 <= n <= 10^4
0 <= len(strs[i]) <= 100
Strings contain lowercase English letters only.
Example
Input
6
eat tea tan ate nat bat
Output
eat tea ate
tan nat
bat