← 返回 amazon 的题目列表Minimum Increment/Decrement Operations to Zero Array
类型:online_judge
amazon
Given an integer array, convert all its elements to 0. At any moment, you can choose a prefix of the array and perform either an increment or decrement operation on all elements within that prefix. Calculate and output the minimum number of operations required to make the array all zeros. The input is an integer array nums with n elements (-10^9 <= nums[i] <= 10^9, 1 <= n <= 10^5), and the output is the minimum number of operations.
Example: Input: [1, 2, 3, -4], Output: 10
Example
Input
[1, 2, 3, -4]