# Remove duplicates from a linked List in C#

Problem source: HackerRank -More Linked Lists

You have a linked list that has n Nodes and their data is in ascending order. A Node object has an integer data field, data, and a Node instance pointer, , pointing to another node (i.e.: the next node in a list). our task is to write a method to remove duplicates from this list and print remaining nodes.

Sample Input

6
1
2
2
3
3
4


Sample Output

1 2 3 4


Explanation

N is total number of Nodes in linked list. The data, 2 and 3 occurs more than one so we need to delete duplicate nodes from the linked list. Once all the duplicate nodes are deleted then print this linked list , which is 1, 2, 3, 4.

class MoreLinkedLists
{
public class Node
{
public int data;
public Node next;
public Node(int d)
{
data = d;
next = null;
}
}
static void Main(string[] args)
{
while (T-- > 0)
{
}

}

{
{
while (start != null)
{
if (start.next != null && start.data == start.next.data)
{
start.next = start.next.next;
}
else
{
start = start.next;
}
}
}
}

public static Node Insert(Node head, int data)
{
Node p = new Node(data);
{
}
{
}
else
{
while (start.next != null)
{
start = start.next;
}
start.next = p;
}
}