From 58ebd8c8b84d6cfd81d65b0d8bd699e116b78e13 Mon Sep 17 00:00:00 2001 From: KaseToatz1337 Date: Thu, 3 Oct 2024 15:32:25 +0200 Subject: [PATCH] fix 1st thingy --- BAI1/Program.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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++; } } }