Intuitive JAVA solution, faster than 100%
I used the most straightforward way to solve this problem.\nIt can be divided into 3 steps.\n Construct tree by using the parents[] array.\n Find the highest sc
I used the most straightforward way to solve this problem.\nIt can be divided into 3 steps.\n* Construct tree by using the parents[] array.\n* Find the highest score\n* Count nodes with the highest score\n\n```\nclass Solution {\n    long highest = 0;\n    \n    public int countHighestScoreNodes(int[] parents) {\n        int n = parents.length;\n        int res = 0;\n        Node[] arr = new Node[n];\n        //construct tree\n        for (int i = 0; i < parents.length; i++) {\n            arr[i] = new Node();\n        }\n        \n        for (int i = 1; i < parents.length; i++) {\n            int parentId = parents[i];\n            if (arr[parentId].left == null) {\n                arr[parentId].left = arr[i];\n            } else {\n                arr[parentId].right = arr[i];\n            }\n        }\n\n        findSize(arr[0]);\n        \n\t\t//find the highest score\n        for (int i = 0; i < parents.length; i++) {\n            long product = 1; \n            int leftCnt = arr[i].left == null ? 0 : arr[i].left.cnt;\n            int rightCnt = arr[i].right == null ? 0 : arr[i].right.cnt;\n            int restCnt = n - 1 - leftCnt - rightCnt;\n            \n            if (leftCnt > 0) {\n                product *= leftCnt;\n            }\n            if (rightCnt > 0) {\n                product *= rightCnt;\n            }\n            if (restCnt > 0) {\n                product *= restCnt;\n            }\n            arr[i].product = product;\n            highest = Math.max(highest, product);\n        }\n        \n\t\t//count nodes\n        for (int i = 0; i < parents.length; i++) {\n            if (arr[i].product == highest) {\n                res++;\n            }\n        }\n        return res;\n    }\n    \n    class Node {\n        Node left;\n        Node right;\n        long product = 0L;\n        int cnt = 0;  \n        public Node() {}\n    }\n    \n    private int findSize (Node root) {\n        if (root == null) {\n            return 0;\n        }\n        int size = findSize(root.left) + findSize(root.right) + 1;\n        root.cnt = size;\n        return size;\n    } \n}\n```
['Recursion']