-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path49.cs
More file actions
21 lines (20 loc) · 708 Bytes
/
Copy path49.cs
File metadata and controls
21 lines (20 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class Solution
{
public IList<IList<string>> GroupAnagrams(string[] strs){
var dictionary_Of_Anagrams = new Dictionary<string, IList<string>>();
foreach (var word in strs){
char[] alfabet = new char[26];
for (int i = 0; i < word.Length; i++)
{
char c = word[i];
alfabet[c - 'a']++;
}
string key = new string(alfabet);
if (!dictionary_Of_Anagrams.ContainsKey(key)){
dictionary_Of_Anagrams[key] = new List<string>();
}
dictionary_Of_Anagrams[key].Add(word);
}
return dictionary_Of_Anagrams.Values.ToList();
}
}