Java Recursion
\n\n\nLet\'s assume the first player took Node 3 in the above tree. \n\nThere are 3 areas to consider: \n- {Node 3\'s left sub tree} (area 1)\n-  {Node 3\'s rig
![image](https://assets.leetcode.com/users/kylinzhuo/image_1586622461.png)\n\n\nLet\'s assume the first player took Node 3 in the above tree. \n\nThere are 3 areas to consider: \n- {Node 3\'s left sub tree} (area 1)\n-  {Node 3\'s right sub tree} (area 2)\n-  {whole tree - subtree with Node 3 as the root} (area 3)\n\nIf player 2 takes Node 3\'s parent node, it means Area 3 cannot be chosen by player 1 anymore, that is to say, It has been RESERVED for player 2 to finish choosing. In this way, Area 1 and 2 are all belonging to Player 1 because of the rule.\n\nIf player 2 takes Node 3\' child node, either Node 6 or Node 7, then Area 3 belongs to Player 1. In addition, if Player 2 chooses Area 1, Area 2 goes to **Player 1** (*p.s. thanks @leetcodenob for pointing the typo out, it was wrong as Player 2*); else if Player 2 chooses Area 2, Area 1 will belong to Player 1. \n\n\n\n\n```java\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n    \n    int left; // Area 1\n    int right; // Area 2\n    \n    public boolean btreeGameWinningMove(TreeNode root, int n, int x) {\n        count(root, x);\n        int p = n - (this.left + this.right + 1); // Area 3\n        return Math.max(p, Math.max(this.left, this.right)) > n/2;\n    }\n    \n    int count(TreeNode node, int x) {\n        if (node == null) {\n            return 0;\n        }\n        int left = count(node.left, x);\n        int right = count(node.right, x);\n\t\t\n        if (node.val == x) { // assign the value to Area 1 and Area 2\n            this.left = left;\n            this.right = right;\n        }\n        return 1 + left + right;\n    }\n}\n```
[]