-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
30 lines (25 loc) · 800 Bytes
/
Solution.cs
File metadata and controls
30 lines (25 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LeetCode.P49;
public class Solution
{
public IList<IList<string>> GroupAnagrams(string[] strs)
{
var orderedAnagrams = new ConcurrentDictionary<string, IList<string>>();
Parallel.ForEach(strs, str =>
{
var key = new string(str.OrderBy(c => c).ToArray());
orderedAnagrams.AddOrUpdate(
key: key,
addValue: new List<string>() { str },
updateValueFactory: (_, values) =>
{
values.Add(str);
return values;
});
});
return (IList<IList<string>>)orderedAnagrams.Values;
}
}