Minmum Steps to Make Array Non Decreasing
Description
Intuition
If we have already make [0, i - 1] using the min steps, what should we do with the nums[i]?
- If
nums[i] >= maxInTheResultArray- 这个可以坐下,是正常操作,直接append到现在的array
- If
nums[i] < maxInTheResultArray- 这个时候我们有两种选择,
- 将
nums[i]increase到maxInTheResultArray, sosteps = maxInTheResultArray - nums[i]and we will append anmaxInTheResultArray - 将所有的大于
nums[i]decrease到nums[i],但是此种方法,steps至少是maxInTheResultArray - nums[i]
- 将
- 无论那种情况,
steps都相同
- 这个时候我们有两种选择,