class Solution {
public boolean checkPossibility(int[] nums) {
int n = nums.length, count = 0;
for (int i = 0; i + 1 < n; i++) {
if (nums[i] > nums[i + 1]) {
count++;
if (i > 0 && nums[i + 1] < nums[i  1]) nums[i + 1] = nums[i];
else nums[i] = nums[i + 1];
}
}
return count <= 1;
}
}
Java solution, 7 liner.


@BatCoder I think
if
condition checksi > 0
first, ifi == 0
then the rest part will not be checked



@AllegroLeonLi You are right. It can be done without that
else
part as well. The solution gets accepted without it.