package greedy;

/**
 * Created by Yue on 2017/11/4.
 * 665. Non-decreasing Array
 */
public class NonDecreasingArray {

    public static boolean checkPossibility(int[] nums) {
        if (nums.length <= 2)
            return true;
        int count = 0;
        for (int i = 0; i < nums.length - 1 && count <= 1; i++) {
            if (nums[i] > nums[i + 1]) {
                count++;
                nums[i] = nums[i + 1];
            }
        }
        return count <= 1;
    }

    public static void main(String[] args) {
        int[] nums = new int[] {3, 4, 2, 3};
        System.out.println(checkPossibility(nums));
    }
}

@@ -175,63 +175,8 @@
 ) %7B%0A
-        if (nums.length %3C= 2)%0A            return true;%0A
     
@@ -215,17 +215,17 @@
 int i = 
-0
+1
 ; i %3C nu
@@ -237,26 +237,8 @@
 ngth
- - 1 && count %3C= 1
 ; i+
@@ -264,16 +264,20 @@
  (nums%5Bi
+ - 1
 %5D %3E nums
@@ -278,20 +278,16 @@
 %3E nums%5Bi
- + 1
 %5D) %7B%0A   
@@ -327,25 +327,47 @@
     
+ if (i - 2 %3C 0 %7C%7C
  nums%5Bi
+ - 2
 %5D 
+%3C
 = nums%5Bi
  + 1
@@ -366,10 +366,73 @@
 ms%5Bi
- +
+%5D) nums%5Bi - 1%5D = nums%5Bi%5D;%0A                else nums%5Bi%5D = nums%5Bi -
  1%5D;

add leetcode no.665