All problems

Problem 118

Remove Duplicates from Sorted List

Easy · 10 pts · Linked List

Problem

You are given a linked list sorted in non-decreasing order, so equal values are next to each other. Delete the extra copies so that each value appears exactly once, and print the list. The first node of each value is kept. Walk through the list once: while the next node has the same value as the current node, skip over it; otherwise move forward.

Input

First line: integer N, the number of nodes. Second line: the N node values from head to tail.

Output

Print the node values of the resulting list from head to tail, space-separated, or EMPTY if it has no nodes.

Constraints

0 <= N <= 300; -100 <= value <= 100; the list is sorted

Example input

3
1 1 2

Example output

1 2

Explanation

In 1 1 2, the second node repeats the value 1 and is removed, leaving 1 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Palindrome Linked List Next: Remove All Duplicates from Sorted List