package leetcode;

/**
 * https://leetcode.com/problems/can-place-flowers/
 */
public class Problem605 {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem605 prob = new Problem605();
        System.out.println(prob.canPlaceFlowers(new int[]{1, 0, 0, 0, 1}, 1)); // true
        System.out.println(prob.canPlaceFlowers(new int[]{1, 0, 0, 0, 1}, 2)); // false
        System.out.println(prob.canPlaceFlowers(new int[]{1, 0, 1, 0, 1}, 2)); // false
        System.out.println(prob.canPlaceFlowers(new int[]{1, 0, 1, 0, 1}, 3)); // false
        System.out.println(prob.canPlaceFlowers(new int[]{0, 0, 0, 0, 0, 0, 1}, 3)); // true
        System.out.println(prob.canPlaceFlowers(new int[]{0, 0, 0, 1, 0, 0, 1}, 1)); // true
        System.out.println(prob.canPlaceFlowers(new int[]{0, 0, 0, 1, 0, 0, 1}, 2)); // false
    }
}

@@ -171,15 +171,937 @@
     
-// TODO
+int idx = 0;%0A        int flowers = 0;%0A        boolean foundOne = false;%0A        for (int i = 0; i %3C flowerbed.length; i++) %7B%0A            if (flowerbed%5Bi%5D == 1) %7B%0A                foundOne = true;%0A                int zeros = i - idx;%0A                if (flowerbed%5Bidx%5D == 1) %7B%0A                    zeros--;%0A                %7D%0A                if (zeros %3E= 2) %7B%0A                    if (flowerbed%5Bidx%5D == 1) %7B%0A                        flowers += (zeros - 1) / 2;%0A                    %7D else %7B%0A                        flowers += zeros / 2;%0A                    %7D%0A                %7D%0A                idx = i;%0A            %7D%0A        %7D%0A        if (!foundOne) %7B%0A            flowers += (flowerbed.length + 1) / 2;%0A        %7D else %7B%0A            int zeros = flowerbed.length - idx;%0A            if (flowerbed%5Bidx%5D == 1) %7B%0A                zeros--;%0A            %7D%0A            if (zeros %3E= 2) %7B%0A                flowers += zeros / 2;%0A            %7D%0A        %7D
 %0A   
@@ -1113,20 +1113,27 @@
 return f
-alse
+lowers %3E= n
 ;%0A    %7D%0A
@@ -1849,20 +1849,746 @@
 ); // false%0A
+        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B1, 0, 0, 0, 1, 0, 0%7D, 2)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B0%7D, 1)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B0, 0%7D, 1)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B1%7D, 1)); // false%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B1%7D, 0)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B1, 0%7D, 1)); // false%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B0, 0, 0%7D, 2)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B0, 0, 0, 0%7D, 2)); // true%0A        System.out.println(prob.canPlaceFlowers(new int%5B%5D%7B0, 0, 0, 0%7D, 3)); // false%0A
     %7D%0A%7D%0A

Update problem 605