1361. Validate Binary Tree Nodes Medium

@problem@discussion
#Tree#Depth-First Search#Breadth-First Search#Union Find#Graph#Binary Tree



1/**
2 * [1361] Validate Binary Tree Nodes
3 *
4 * You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree.
5 * If node i has no left child then leftChild[i] will equal -1, similarly for the right child.
6 * Note that the nodes have no values and that we only use the node numbers in this problem.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2019/08/23/1503_ex1.png" style="width: 195px; height: 287px;" />
10 * Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,-1,-1,-1]
11 * Output: true
12 * 
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2019/08/23/1503_ex2.png" style="width: 183px; height: 272px;" />
15 * Input: n = 4, leftChild = [1,-1,3,-1], rightChild = [2,3,-1,-1]
16 * Output: false
17 * 
18 * Example 3:
19 * <img alt="" src="https://assets.leetcode.com/uploads/2019/08/23/1503_ex3.png" style="width: 82px; height: 174px;" />
20 * Input: n = 2, leftChild = [1,0], rightChild = [-1,-1]
21 * Output: false
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	n == leftChild.length == rightChild.length
27 * 	1 <= n <= 10^4
28 * 	-1 <= leftChild[i], rightChild[i] <= n - 1
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/validate-binary-tree-nodes/
34// discuss: https://leetcode.com/problems/validate-binary-tree-nodes/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn validate_binary_tree_nodes(n: i32, left_child: Vec<i32>, right_child: Vec<i32>) -> bool {
40        false
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_1361() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.