Non-decreasing Array – LeetCode 665
Problem
Description
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).
Answer
Original
Code
1 | class Solution { |
思路
针对具体情况分类讨论。时间复杂度$O(n)$,空间复杂度$O(1)$。
耗时$24$ ms,排名$5.91\%$
Better
思路
还没见到更好的思路