n個のリストを比較し、すべてのリストに表示されないすべての値を返すメソッドを作成する最も効率的な方法は何ですか。
var lists = new List<List<int>> {
new List<int> { 1, 2, 3, 4 },
new List<int> { 2, 3, 4, 5, 8 },
new List<int> { 2, 3, 4, 5, 9, 9 },
new List<int> { 2, 3, 3, 4, 9, 10 }
};
public IEnumerable<T> GetNonShared(this IEnumerable<IEnumerable<T>> lists)
{
//...fast algorithm here
}
となることによって
lists.GetNonShared();
1、5、8、9、10を返します
私は持っていた
public IEnumerable<T> GetNonShared(this IEnumerable<IEnumerable<T>> lists)
{
return list.SelectMany(item => item)
.Except(lists.Aggregate((a, b) => a.Intersect(b));
}
しかし、それが効率的かどうかはわかりませんでした。順序は関係ありません。ありがとう!