+ 1

Duplicate remover not working properly.

https://code.sololearn.com/ctlfewg3nRgb/?ref=app

25th Jul 2020, 9:31 AM
Tricker
3 Antworten
+ 1
You're accessing the same array which you are iterating based on its index. So, if you erase one element and reduce the size, you fulfill the stop condition, but you'll also skip one element: 122322 Erase x = 1, new array 12322 Next x = 2, value 3 Next x = 3, value 2 Erase x = 3, new array 1232 Next x = 4 < size So you are missing the number of elements, which you reduced the size for at the end of each array.
25th Jul 2020, 12:55 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
25th Jul 2020, 1:11 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Sandra Meyer thanks for pointing out the error. That helped me to come up with a solution: https://code.sololearn.com/c2968L8hLXCc/?ref=app
26th Jul 2020, 7:11 AM
Tricker