在整數列表中找到重複項的最佳方式是什麼?(不管他們處於什麼位置)?我不需要代碼就是解決這個問題的最好方法(在C#中)。在整數列表中找到重複項
如:
List<List<int>> TestData = new List<List<int>>
{
new List<int> { 1, 2, 3 },
new List<int> { 2, 1, 3 },
new List<int> { 6, 8, 3, 45,48 },
new List<int> { 9, 2, 4 },
new List<int> { 9, 2, 4, 15 },
};
的想法是,這將返回
Count | Set
----------------
2x | 1,2,3
1x | 6, 8, 3, 45, 48
1x | 9,2,4
1x | 9, 2, 4, 15
我已經打破了我的頭在這個看似很簡單的問題,但由於某種原因,我想不出它出。希望有人能夠幫助,就像我說的代碼沒有必要,但非常感謝。
定義最佳方式 - 最短代碼,最佳性能(以及哪一個 - 內存/速度)? –
你可以使用字典或散列表來實現這個 – Prabu
也許你應該嘗試'Linq' ...'TestData.Select(L => L.Sort())。GroupBy(x => x)'=>返回的值是按列表分組 –