Fastest way to find common items across multiple lists in C#

后端 未结 11 1833

Given the following:

List> optionLists;

what would be a quick way to determine the subset of Option objects that a

11条回答
  •  盖世英雄少女心
    2021-01-19 02:50

    Sort, then do something akin to a merge-sort.

    Basically you would do this:

    1. Retrieve the first item from each list
    2. Compare the items, if equal, output
    3. If any of the items are before the others, sort-wise, retrieve a new item from the corresponding list to replace it, otherwise, retrieve new items to replace them all, from all the list
    4. As long as you still got items, go back to 2.

提交回复
热议问题