← 返回 meta 的题目列表Subtract Until Zero or Less
类型:online_judge
Given an integer array, repeatedly choose the first non-zero element and subtract the value of the first element from it. Repeat this until all elements become zero or you encounter a strictly less value than the current processing element.
Input:
A non-negative integer array arr
Output:
The array at the time processing ends
Example:
Input: [3, 3, 2, 1, 1]
Output: [0, 0, 1, 1, 1]
Explanation: Subtract 3 from the two leading 3s to get [0, 0, 2, 1, 1], then subtract 2, finally reaching [0, 0, 1, 1, 1].
Data Scale:
The length of array arr is at most 1000.
Example
Input
[3, 3, 2, 1, 1]