educative.io

Educative

It is great challenge, I got it

It is great! I pass through it by myself.

public static <T> void removeDuplicates(SinglyLinkedList<T> list) {

    if (list.isEmpty()) return;

    SinglyLinkedList<T>.Node node = list.getHeadNode();
    SinglyLinkedList<T>.Node current = null;
    SinglyLinkedList<T>.Node prev = null;

    while (node != null)
    {
        current = node.nextNode;
        prev = node;
        while (current != null)
        {
            if (current.data.equals(node.data))
            {
                prev.nextNode = current.nextNode;
            }
            else
            {
                prev = prev.nextNode;
            }
            current = current.nextNode;
        }

        node = node.nextNode;
    }

}
1 Like

Hi Bo,

We are so glad to hear that you are enjoying learning from this course :smile:. Excellent job on solving the challenge!

We love to hear from you.

Best Regards,
Fatimah Abdullah | Developer Advocate
Educative Inc.

2 Likes