|
5 | 5 | importjava.util.List;
|
6 | 6 | importjava.util.Map;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * 1361. Validate Binary Tree Nodes |
10 |
| - * |
11 |
| - * You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], |
12 |
| - * return true if and only if all the given nodes form exactly one valid binary tree. |
13 |
| - * If node i has no left child then leftChild[i] will equal -1, similarly for the right child. |
14 |
| - * Note that the nodes have no values and that we only use the node numbers in this problem. |
15 |
| - * |
16 |
| - * Example 1: |
17 |
| - * Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1] |
18 |
| - * Output: true |
19 |
| - * |
20 |
| - * Example 2: |
21 |
| - * Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1] |
22 |
| - * Output: false |
23 |
| - * |
24 |
| - * Example 3: |
25 |
| - * Input: n = 2, leftChild = [1,0], rightChild = [-1,-1] |
26 |
| - * Output: false |
27 |
| - * |
28 |
| - * Example 4: |
29 |
| - * Input: n = 6, leftChild = [1,-1,-1,4,-1,-1], rightChild = [2,-1,-1,5,-1,-1] |
30 |
| - * Output: false |
31 |
| - * |
32 |
| - * Constraints: |
33 |
| - * 1 <= n <= 10^4 |
34 |
| - * leftChild.length == rightChild.length == n |
35 |
| - * -1 <= leftChild[i], rightChild[i] <= n - 1 |
36 |
| - * */ |
37 | 8 | publicclass_1361 {
|
38 | 9 | publicstaticclassSolution1 {
|
39 | 10 | publicbooleanvalidateBinaryTreeNodes(intn,int[]leftChild,int[]rightChild) {
|
|