Tap here to switch tabs
Problem
Submissions

Problem: Validate Binary Tree Nodes

Try to solve the Validate Binary Tree Nodes problem.

Statement

You are given nn binary tree nodes numbered from 00 to n −1- 1. For each node i, its left child is leftChild[i] and its right child is rightChild[i]. If a node i has no left child, leftChild[i] is −1-1. Similarly, if it has no right child, rightChild[i] is −1-1.

Return true if and only if all given nodes form exactly one valid binary tree. Otherwise, return false.

Constraints:

  • n ==== leftChild.length ==== rightChild.length

  • 1≤1 \le n ≤104\le 10^4

  • −1≤-1 \le leftChild[i], rightChild[i] ≤\le n −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Validate Binary Tree Nodes

Try to solve the Validate Binary Tree Nodes problem.

Statement

You are given nn binary tree nodes numbered from 00 to n −1- 1. For each node i, its left child is leftChild[i] and its right child is rightChild[i]. If a node i has no left child, leftChild[i] is −1-1. Similarly, if it has no right child, rightChild[i] is −1-1.

Return true if and only if all given nodes form exactly one valid binary tree. Otherwise, return false.

Constraints:

  • n ==== leftChild.length ==== rightChild.length

  • 1≤1 \le n ≤104\le 10^4

  • −1≤-1 \le leftChild[i], rightChild[i] ≤\le n −1- 1