665.java

Home   »   665.java

class Solution {
    public boolean checkPossibility(int[] nums) {
        int count = 0;
        
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] < nums[i-1]) {
                count++;
                if (i < 2 || nums[i-2] <= nums[i]) nums[i-1] = nums[i];
                else nums[i] = nums[i-1];
            }
        }
        return count < 2;
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *