package leetcode;

/**
 * https://leetcode.com/problems/binary-tree-coloring-game/
 */
public class Problem1145 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public boolean btreeGameWinningMove(TreeNode root, int n, int x) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1145 prob = new Problem1145();

        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        root.left.left = new TreeNode(4);
        root.left.right = new TreeNode(5);
        root.right.left = new TreeNode(6);
        root.right.right = new TreeNode(7);
        root.left.left.left = new TreeNode(8);
        root.left.left.right = new TreeNode(9);
        root.left.right.left = new TreeNode(10);
        root.left.right.right = new TreeNode(11);

        System.out.println(prob.btreeGameWinningMove(root, 11, 3)); // true
        System.out.println(prob.btreeGameWinningMove(root, 11, 2)); // false
    }
}

@@ -12,16 +12,93 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -431,36 +431,1265 @@
     
-// TODO%0A        return false
+int%5B%5D counts = new int%5Bn + 1%5D;%0A        getChildCount(root, counts);%0A        System.out.println(Arrays.toString(counts));%0A        List%3CInteger%3E adjacents = new ArrayList%3C%3E();%0A        getAdjacents(null, root, x, adjacents);%0A        System.out.println(adjacents);%0A        return false;%0A    %7D%0A%0A    private static void getAdjacents(TreeNode parent, TreeNode current,%0A                                     int x, List%3CInteger%3E adjacents) %7B%0A        if (current == null) %7B%0A            return;%0A        %7D%0A        if (current.val == x) %7B%0A            if (parent != null) %7B%0A                adjacents.add(parent.val);%0A            %7D%0A            if (current.left != null) %7B%0A                adjacents.add(current.left.val);%0A            %7D%0A            if (current.right != null) %7B%0A                adjacents.add(current.right.val);%0A            %7D%0A            return;%0A        %7D%0A        getAdjacents(current, current.left, x, adjacents);%0A        getAdjacents(current, current.right, x, adjacents);%0A    %7D%0A%0A    private static int getChildCount(TreeNode root, int%5B%5D counts) %7B%0A        if (root == null) %7B%0A            return 0;%0A        %7D%0A        int count = getChildCount(root.left, counts) + getChildCount(root.right, counts) + 1;%0A        counts%5Broot.val%5D = count;%0A        return count
 ;%0A  
@@ -2344,16 +2344,18 @@
 // true%0A
+//
         
@@ -2423,16 +2423,94 @@
 / false%0A
+//        System.out.println(prob.btreeGameWinningMove(root, 11, 1)); // true%0A
     %7D%0A%7D%0A

Update problem 1145