package leetcode;

/**
 * https://leetcode.com/problems/fruit-into-baskets/
 */
public class Problem904 {
    public int totalFruit(int[] tree) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem904 prob = new Problem904();
        System.out.println(prob.totalFruit(new int[]{1, 2, 1})); // 3
        System.out.println(prob.totalFruit(new int[]{0, 1, 2, 2})); // 3
        System.out.println(prob.totalFruit(new int[]{1, 2, 3, 2, 2})); // 4
        System.out.println(prob.totalFruit(new int[]{3, 3, 3, 1, 2, 1, 1, 2, 3, 3, 4})); // 5
    }
}

@@ -151,33 +151,986 @@
     
-// TODO%0A        return 0;
+int answer = 0;%0A        TypeCount%5B%5D tc = new TypeCount%5B2%5D;%0A        for (int i = 0; i %3C tree.length; i++) %7B%0A            if (tc%5B0%5D == null) %7B%0A                tc%5B0%5D = new TypeCount(tree%5Bi%5D);%0A                tc%5B0%5D.count++;%0A            %7D else if (tree%5Bi%5D == tc%5B0%5D.type) %7B%0A                tc%5B0%5D.count++;%0A            %7D else if (tc%5B1%5D == null) %7B%0A                tc%5B1%5D = new TypeCount(tree%5Bi%5D);%0A                tc%5B1%5D.count++;%0A            %7D else if (tree%5Bi%5D == tc%5B1%5D.type) %7B%0A                tc%5B1%5D.count++;%0A            %7D else %7B%0A                tc%5B0%5D = tc%5B1%5D;%0A                tc%5B1%5D = new TypeCount(tree%5Bi%5D);%0A                tc%5B1%5D.count++;%0A            %7D%0A            answer = Math.max(answer, (tc%5B0%5D == null ? 0 : tc%5B0%5D.count) +%0A                (tc%5B1%5D == null ? 0 : tc%5B1%5D.count));%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static class TypeCount %7B%0A        private final int type;%0A        private int count;%0A%0A        public TypeCount(int num) %7B%0A            this.type = num;%0A        %7D
 %0A   
@@ -1222,16 +1222,18 @@
 m904();%0A
+//
         
@@ -1286,32 +1286,34 @@
 , 2, 1%7D)); // 3%0A
+//
         System.o
@@ -1369,16 +1369,18 @@
 ); // 3%0A
+//
         
@@ -1447,16 +1447,18 @@
 ); // 4%0A
+//
         
@@ -1543,16 +1543,104 @@
 ); // 5%0A
+        System.out.println(prob.totalFruit(new int%5B%5D%7B1, 0, 1, 4, 1, 4, 1, 2, 3%7D)); // 5%0A
     %7D%0A%7D%0A

Update problem 904