Description
Given an array nums with n integers, check if it could become non-decreasing by modifying at most one element. Non-decreasing means nums[i] <= nums[i+1].
Examples
Input:
nums = [4,2,3]Output:
trueExplanation:
Change 4 to 1.
Input:
nums = [4,2,1]Output:
falseExplanation:
For nums = [4,2,1], the answer is false because the non-decreasing array condition is not met.
Input:
nums = [1,3,2,4]Output:
trueExplanation:
Modify the array by changing 3 to 2 (or 2 to 3), resulting in [1,2,2,4] which is non-decreasing. Only one modification is needed.
Constraints
- •
1 ≤ n ≤ 10⁴