LINQ联盟与重复

Zer*_*nes 1 c# linq

假设我们有以下三个列表:

{ 1, 2, 2, 3 }
{ 2, 3, 3, 4 }
{ 2, 3, 4, 5, 5, 5 }
Run Code Online (Sandbox Code Playgroud)

然后我们如何将上面的内容转换为一个列表,让每个项目重复在list.ie中找到的最大次数.

{1, 2, 2 (Found twice in list 1), 3, 3 (Twice in list 2), 4, 5, 5, 5 (Thrice in list 3)}
Run Code Online (Sandbox Code Playgroud)

我可以通过循环实现上述,但是,我正在寻找可能已经存在的LINQ方法.

问题类似于在python中使用重复项的列表联合

fub*_*ubo 5

Linq在一条线上

int[][] items = { new[]{ 1, 2, 2, 3 }, new[] { 2, 3, 3, 4 }, new[] { 2, 3, 4, 5, 5, 5 } };
var result = items.SelectMany(x => x.GroupBy(y => y)).GroupBy(x => x.Key).Select(x => x.OrderByDescending(y => y.Count()).First()).SelectMany(x => x);
Run Code Online (Sandbox Code Playgroud)

https://dotnetfiddle.net/kZhseg