我想合併具有公共元素的數組。我有數組列表如下:合併具有公共元素的數組
List<int[]> arrList = new List<int[]>
{
new int[] { 1, 2 },
new int[] { 3, 4, 5 },
new int[] { 2, 7 },
new int[] { 8, 9 },
new int[] { 10, 11, 12 },
new int[] { 3, 9, 13 }
};
,我想合併這些陣列是這樣的:
List<int[]> arrList2 = new List<int[]>
{
new int[] { 1, 2, 7 },
new int[] { 10, 11, 12 },
new int[] { 3, 4, 5, 8, 9, 13 } //order of elements doesn't matter
};
怎麼辦呢?
在你的情況下,您如何我們合併的事情,如果'3'處處定義?一個數組? –
合併背後的邏輯是什麼? –
@SimonBelanger:是的,如果所有數組中都有'3',那麼將會合併成一個數組 – user2804123