• + 0 comments

    C#

    public static Node removeDuplicates(Node head)
        {
            //Write your code here
            //My answer
            if (head.next is not null)
            {
                Node next = head.next;
                while (next.next is not null)
                {
                    Node next2 = next.next;
                    if (next.data == next2.data)
                    {
                        next.next = next2.next;
                    }
                    else
                    {
                        next = next.next;
                    }
                }
    
                next = head.next;
                if (head.data == next.data)
                {
                    head.next = next.next;
                }
    
            }
    
            return head;
        }