Non-decreasing Array
Solution to “Non-decreasing Array” problem.
class Solution {
public boolean checkPossibility(int[] nums) {
int max = Integer.MIN_VALUE;
int c = 0;
for (int i = 0; i < nums.length; i ++) {
if (max <= nums[i]) {
max = nums[i];
} else {
c ++;
}
}
int min = Integer.MAX_VALUE;
int d = 0;
for (int i = nums.length - 1; i >= 0; i --) {
if (min >= nums[i]) {
min = nums[i];
} else {
d ++;
}
}
return ((c <= 1 || d <= 1) ? true : false);
}
}
Credit goes to this guy.