Duplicate remover not working properly. | SoloLearn: Learn to code for FREE!


Duplicate remover not working properly.



7/25/2020 9:31:33 AM


3 Answers

New Answer


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.


See here, a possible solution: https://code.sololearn.com/cZy6Kj8iqLU7/?ref=app


Sandra Meyer thanks for pointing out the error. That helped me to come up with a solution: https://code.sololearn.com/c2968L8hLXCc/?ref=app