我想合并具有公共元素的数组。我有数组列表如下:合并具有公共元素的数组
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