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. var list = new[] { 80,81,90,90,90,90,90,90,100,85,86,86,79,95,95,95,95 };
  10. var dupes = FindDupes(list);
  11. Console.WriteLine(string.Join(", ", dupes.Select(n => n.ToString()).ToArray()));
  12. }
  13.  
  14. public static IEnumerable<int> FindDupes(IEnumerable<int> list) {
  15. int? back2 = null, back1 = null, prev = null;
  16. foreach(int current in list) {
  17. if(back2.HasValue) {
  18. if(back2.Value == back1.Value && back1.Value == current) {
  19. if(!prev.HasValue || prev.Value != current) {
  20. yield return current;
  21. prev = current;
  22. }
  23. }
  24. }
  25.  
  26. back2 = back1;
  27. back1 = current;
  28. }
  29. }
  30. }
Success #stdin #stdout 0.04s 33936KB
stdin
Standard input is empty
stdout
90, 95