#C14652. Remove Duplicates from List
Remove Duplicates from List
Remove Duplicates from List
Given a list of integers, your task is to remove all duplicate values while preserving the original order of the elements. Implement a function remove_duplicates
that reads the list of integers, eliminates repeated elements, and returns a list containing only the first occurrence of each integer.
For example, if the input is [1, 2, 2, 3, 4, 4, 5]
, the output should be [1, 2, 3, 4, 5]
. The relative order of the elements must remain unchanged.
In formal terms, if the input list is \(a_1, a_2, \ldots, a_n\), then the output list should be \(b_1, b_2, \ldots, b_k\) where \(b_1 = a_{i_1}, b_2 = a_{i_2}, \ldots, b_k = a_{i_k}\) and \(i_1 < i_2 < \cdots < i_k\); and for each \(j\), \(a_{i_j}\) is the first occurrence of that value in the list.
Note: All formulas are written in \(\LaTeX\) format. For instance, the requirement can be stated as: \(\forall i,\, 1 \leq i \leq n,\,\exists j,\, 1 \leq j \leq k\) such that \(a_i = b_j\) and if \(a_i = a_m\) with \(i < m\), then \(b_j\) appears only once.
inputFormat
The input is provided via standard input (stdin) as a single line containing space-separated integers. For example: 1 2 2 3 4 4 5
. If the input line is empty, it should be treated as an empty list.
outputFormat
The output should be printed to standard output (stdout) as a single line of space-separated integers representing the list after duplicates have been removed while preserving the original order. If the list is empty, print an empty line.
## sample1 2 2 3 4 4 5
1 2 3 4 5