665. Non-decreasing Array
Given an array with n
integers, your task is to check if it could become non-decreasing by modifying at most 1
element.
We define an array is non-decreasing if array[i] <= array[i + 1]
holds for every i
(1 <= i < n).
Example 1:
Example 2:
解题要点:
从i = 1开始,如若当前数大于等于前一位数(符合递增规则)直接进入下一位数。如当前数i >= 2 且小于前前位数,则赋当前值为前一位数;反之,赋前一位值为当前值。
Last updated
Was this helpful?