So my code is basically this:
List list = new List(new int[] { 1, 5, 8, 8, 8, 2, 3, 3, 4, }); list = RemoveDuplicats(list);
public static List<int> RemoveDuplicats(List<int> list)
{
int i = 0;
while (i<list.Count)
{
if (list[i] == list[i+1])
{
list.RemoveAt(list[i + 1]);
return list;
}
i++;
}
return list;
}
It seems like RemoveAt is not working or it's being skipped entirely. So what i should be getting is 1,5,8,2,3,4 but it just prints original list. Where'd i go wrong?