You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a problem at 11_13,
if there are three continuous 4, the output list will have two 4s.
I think, for example, j is 5 now. After removing num1 of 5th, the num2 of 6th will move to 5th. Then j++. It leads to that num2 was passed. In other words, the for loop skiped some elements.
Change it toif(...){..} else{ j++;} may be worked. It will j++ only if if-condition is false.
/* i have a solution for this */
public static void removeDuplicate(ArrayList list) {
for (int i = 0; i < list.size(); i++) {
Integer obj = new Integer(list.get(i));
while (list.lastIndexOf(obj) != -1 && list.lastIndexOf(obj) != list.indexOf(obj)) {
list.remove(list.lastIndexOf(obj));
}
}
}
Activity
erenkrabulut commentedon Jul 14, 2023
/* i have a solution for this */
public static void removeDuplicate(ArrayList list) {
for (int i = 0; i < list.size(); i++) {
Integer obj = new Integer(list.get(i));
while (list.lastIndexOf(obj) != -1 && list.lastIndexOf(obj) != list.indexOf(obj)) {
list.remove(list.lastIndexOf(obj));
}
}
}