|
2 | 2 |
|
3 | 3 | importjava.util.Arrays; |
4 | 4 |
|
5 | | -/** |
6 | | - * 1273. Delete Tree Nodes |
7 | | - * |
8 | | - * A tree rooted at node 0 is given as follows: |
9 | | - * The number of nodes is nodes; |
10 | | - * The value of the i-th node is value[i]; |
11 | | - * The parent of the i-th node is parent[i]. |
12 | | - * Remove every subtree whose sum of values of nodes is zero. |
13 | | - * After doing so, return the number of nodes remaining in the tree. |
14 | | - * |
15 | | - * Example 1: |
16 | | - * 0 (1) |
17 | | - * / \ |
18 | | - * (-2) 1 2 (4) |
19 | | - * / / | \ |
20 | | - * (0)3 (-2)4 (-1)5 6(-1) |
21 | | - * |
22 | | - * Input: nodes = 7, parent = [-1,0,0,1,2,2,2], value = [1,-2,4,0,-2,-1,-1] |
23 | | - * Output: 2 |
24 | | - * |
25 | | - * Constraints: |
26 | | - * 1 <= nodes <= 10^4 |
27 | | - * -10^5 <= value[i] <= 10^5 |
28 | | - * parent.length == nodes |
29 | | - * parent[0] == -1 which indicates that 0 is the root. |
30 | | - * */ |
31 | 5 | publicclass_1273 { |
32 | 6 | publicstaticclassSolution1 { |
33 | 7 | publicintdeleteTreeNodes(intnodes,int[]parent,int[]value) { |
|