#K84357. Remove Zeros from a Linked List
Remove Zeros from a Linked List
Remove Zeros from a Linked List
You are given a singly linked list containing integer values. Your task is to remove every node which has a value of \(0\) from the linked list and then output the resulting linked list. The linked list should be printed as a space-separated sequence of integers. If the linked list becomes empty after removing all the zeros, output an empty line.
The linked list is provided as input in the following format:
- The first line contains an integer \(N\) — the number of nodes in the linked list.
- The second line contains \(N\) space-separated integers representing the values of the nodes.
Example:
For the input:
5 0 1 2 0 3
The output should be:
1 2 3
Utilize standard input (stdin) for reading inputs and standard output (stdout) for printing the result.
inputFormat
The first line of input contains an integer \(N\), the number of nodes in the linked list.
The second line contains \(N\) space-separated integers which represent the node values of the linked list.
outputFormat
After removing all nodes with value zero, output the remaining linked list as a sequence of space-separated integers in one line. If the resulting linked list is empty, output an empty line.
## sample5
0 1 2 0 3
1 2 3