RobloxOA #11
Make Towers Strictly Increasing or Decreasing
估计中等评测数据准备中,可先阅读题面
给一个整数数组 towers。每次操作可对任一塔加 1 或减 1,cost 为 1。求把数组改成"严格递增"或"严格递减"的最小总操作数。返回较小者。
Example 1
Input:
towers = [1, 4, 3, 2]
Output:
4
Explanation: The given array can be transformed into a valid strictly monotonic sequence at the cost shown.
Example 2
Input:
towers = [5, 7, 9, 4, 11]
Output:
9
Explanation: The given array can be transformed into a valid strictly monotonic sequence at the cost shown.