fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. List<List<int>> lst = new List<List<int>>();
  10. lst.Add(new List<int> { 1 });
  11. lst.Add(new List<int> { 2 });
  12. lst.Add(new List<int> { 3 });
  13. lst.Add(new List<int> { 4, 5 });
  14. lst.Add(new List<int> { 7 });
  15. lst.Add(new List<int> { 4, 5 });
  16. lst.Add(new List<int> { 1 });
  17. lst.Add(new List<int> { 3 });
  18.  
  19. var newList = lst.GroupBy(x => x, new Compare()).Where(x => x.Count() == 1).SelectMany(x => x);
  20.  
  21. foreach (var x in newList)
  22. Console.WriteLine(string.Join(" ", x));
  23. }
  24.  
  25. }
  26. public class Compare : IEqualityComparer<List<int>>
  27. {
  28. public bool Equals(List<int> x, List<int> y)
  29. {
  30. if (x.Count != y.Count) return false;
  31. int n = x.Count;
  32. for (int i = 0; i < n; i++)
  33. if (x[i] != y[i])
  34. return false;
  35.  
  36. return true;
  37. }
  38. public int GetHashCode(List<int> x)
  39. {
  40. return 0;
  41. }
  42. }
Success #stdin #stdout 0.05s 24512KB
stdin
Standard input is empty
stdout
2
7