diff --git a/BAI1/Program.cs b/BAI1/Program.cs index 3dc36ad..dbb881f 100644 --- a/BAI1/Program.cs +++ b/BAI1/Program.cs @@ -15,23 +15,27 @@ namespace BAI /// ------------------------------------------------------------ public static void Opdr1FilterList(List lijst) { - Dictionary occurences = []; - foreach (int i in lijst) + Dictionary positions = []; + for (int i = 0; i < lijst.Count; i++) { - if (occurences.TryGetValue(i, out int value)) + if (positions.TryGetValue(lijst[i], out _)) { - occurences[i] = ++value; + positions[lijst[i]] = -1; } else { - occurences[i] = 1; + positions[lijst[i]] = i; } } - foreach (int i in occurences.Keys) + for (int i = 0; i < lijst.Count;) { - if (occurences[i] == 1) + if (positions[lijst[i]] != -1) { - lijst.Remove(i); + lijst.RemoveAt(i); + } + else + { + i++; } } }