Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11_13 #43

Open
AsukaZERO2 opened this issue Feb 18, 2020 · 1 comment
Open

11_13 #43

AsukaZERO2 opened this issue Feb 18, 2020 · 1 comment

Comments

@AsukaZERO2
Copy link

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.

@erenkrabulut
Copy link

/* 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));
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants