← 返回 oracle 的题目列表Compare two N-ary trees for equality
类型:online_judge
Problem
Given the roots root1 and root2 of two N-ary trees, determine whether they are identical.
Two N-ary trees are identical if:
Corresponding node values are equal.
Each corresponding node has the same number of children.
Children order matters (the i-th child must match).
Return true or false.
Input (assumption)
Each tree is given in level-order with null separators between children lists. Example: 1 null 3 2 4 null 5 6.
Input has two lines:
Line 1: tree1 encoding
Line 2: tree2 encoding
Output
Print true or false.
Constraints
0 <= #nodes <= 2e5
Node values are 32-bit integers
Example
Input
1 null 3 2 4 null 5 6
1 null 3 2 4 null 5 6
Output
true