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: Input: [4,2,3] Out…
665. Non-decreasing Array Input: [4,2,3] Output: True Explanation: You could modify the first 4 to 1 to get a non-decreasing array.递增 思路:贪心思想,找异常值,存在两个以上则返回false.如果当前的值比前一的值小,并且也比前两的值小,此时只需更改当前值,而不更改前两个值. 更改规则是用前一的值代替当前值. 两种情况 例如: 2 2 1 -> 2 2…
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: Input: [4,2,3] Out…
package y2019.Algorithm.array; /** * @ClassName FindUnsortedSubarray * @Description TODO 581. Shortest Unsorted Continuous Subarray * * Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending…