#102. 替换零值:右侧最大奇数
替换零值:右侧最大奇数
Replace Zeros
Background
Dawei is working with an array of integers. He wants to perform some special modifications on the array to meet specific conditions.
Problem Description
Return a version of the given array where each zero value in the array is replaced by the largest odd value to the right of the zero in the array. If there is no odd value to the right of the zero, leave the zero as a zero.
Input Format
Input is given from Standard Input in the following format.
A single line containing several space-separated integers, representing the given array.
Output Format
Output to Standard Output in the following format.
Output a single line containing the elements of the modified array, separated by commas and spaces, enclosed in square brackets
[].
Sample
[0 5 0 3]
[5, 5, 3, 3]
[0 4 0 3]
[3, 4, 3, 3]
[0 1 0]
[1, 1, 0]
Sample Explanation
For Sample 1 [0 5 0 3]:
- The first
0has odd numbers5and3to its right. The largest odd number among them is5, so the first0is replaced by5. - The second
0has the odd number3to its right. The largest odd number among them is3, so the second0is replaced by3. - Other elements in the array remain unchanged.
The final result is
[5, 5, 3, 3].
Constraints
Time Limit: 1s, Memory Limit: 1024KiB.