static void Main(string[] args) { ICustomList sample = new CustomList(); sample.Add(2); sample.Add(2); sample.Add(2); sample.Add(3); sample.Add(3); sample.Add(2); sample.Add(3); sample.Add(3); sample.Add(3); sample.Add(3); sample.Add(1); sample.Add(2); ICustomList subSet = sample.FindLongestSubsetOfEquals(); Console.WriteLine("Best sequence:"); Console.Write("{"); for (int index = 0; index < subSet.Count; index++) { Console.Write(subSet[index]); if (index != subSet.Count - 1) { Console.Write(", "); } } Console.WriteLine("}"); }
public ICustomList FindLongestSubsetOfEquals() { ICustomList subSet = new CustomList(); int currBestCount = 0; int bestCountOverAll = 0; int subSetElement = 0; for (int index = 0; index < this.Array.Length - 1; index++) { if (this.Array[index] == this.Array[index + 1]) { currBestCount++; } else { if (currBestCount > bestCountOverAll) { bestCountOverAll = currBestCount; currBestCount = 0; subSetElement = this.Array[index]; } } } for (int i = 0; i < bestCountOverAll; i++) { subSet.Add(subSetElement); } return subSet; }