Skip to content

11_13 #43

Open
Open

Description

@AsukaZERO2

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.

Activity

  1. erenkrabulut commented on Jul 14, 2023

    @erenkrabulut

    /* 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions