请教一道算法题# JobHunting - 待字闺中
m*a
1 楼
Give an integer array, adjust each integers so that the difference of every
adjacent integers are not greater than a given number target. If the array
before adjustment is A, the array after adjustment is B, you should minimize
the sum of abs(A[i] - B[i])
You can assume each number in the array is a positive integer and not
greater than 100
Example:
Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the
adjustment cost is 2 and it's minimal. Return 2.
题目如上,请问大牛们有没有好的想法?谢谢!
adjacent integers are not greater than a given number target. If the array
before adjustment is A, the array after adjustment is B, you should minimize
the sum of abs(A[i] - B[i])
You can assume each number in the array is a positive integer and not
greater than 100
Example:
Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the
adjustment cost is 2 and it's minimal. Return 2.
题目如上,请问大牛们有没有好的想法?谢谢!