#C13212. Remove Duplicates from a Sorted Linked List

    ID: 42726 Type: Default 1000ms 256MiB

Remove Duplicates from a Sorted Linked List

Remove Duplicates from a Sorted Linked List

Given a sorted linked list, your task is to remove all nodes that have duplicate numbers, leaving only nodes with distinct values. For example, if the list is (1 \rightarrow 2 \rightarrow 3 \rightarrow 3 \rightarrow 4 \rightarrow 4 \rightarrow 5), then after removing duplicates, the resulting linked list should be (1 \rightarrow 2 \rightarrow 5). You are required to read input from standard input and output the resulting list to standard output.

inputFormat

The first line contains a single integer (n) representing the number of nodes in the linked list. The second line contains (n) space-separated integers in increasing order representing the elements of the linked list.

outputFormat

Output a single line containing the values of the linked list after removing all duplicates, separated by a space. If the resulting linked list is empty, output an empty line.## sample

1
1
1