#100. 数组去特定元素并填充

    ID: 100 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp7双指针模拟

数组去特定元素并填充

Array Remove 10s and Fill Zeros

Background

Dawei is organizing a list of numbers and wants to remove specific numbers while keeping the list tidy.

Problem Description

Return a version of the given array where all the 10's have been removed. The remaining elements should shift left towards the start of the array as needed, and the empty spaces at the end of the array should be 0. So {1,10,10,2}\{1, 10, 10, 2\} yields {1,2,0,0}\{1, 2, 0, 0\}. You may modify and return the given array or make a new array.

Input Format

Input is given from standard input in the following format.

An array of integers, represented as [a_1 a_2 ... a_N].

Output Format

Output is printed to standard output in the following format.

The modified array, represented as [b_1, b_2, ..., b_N].

Sample

[1 10 10 2]
[1, 2, 0, 0]
[10 2 10]
[2, 0, 0]
[1 99 10]
[1, 99, 0]

Sample Explanation

In the first sample, the 10s are removed, 1 and 2 shift left, and the remaining two positions are filled with 0s. In the second sample, the 10s are removed, 2 shifts left, and the remaining two positions are filled with 0s. In the third sample, the 10 is removed, 1 and 99 shift left, and the remaining position is filled with 0.

Constraints

The length of the array NN satisfies 1N10001 \le N \le 1000. Each element AiA_i in the array satisfies 0Ai1000 \le A_i \le 100. Time limit: 1s, Memory limit: 1024KiB for each test case.