#665
Non-decreasing Array
expert · 1160 · lc medium +32 · verified · 25.4% accepted · 5,853 likes · top 4%
Description
Given an integer array nums, determine whether it is possible to make the array non-decreasing (every element ≤ the next) by changing at most one element. Return true if possible, false otherwise.
Example 1:
Input: nums = [4,2,3]
Output: true
Explanation: You could modify the first 4 to 1 to get a non-decreasing array.
Example 2:
Input: nums = [4,2,1]
Output: false
Explanation: You cannot get a non-decreasing array by modifying at most one element.
Code
1
2
3