← 返回 oracle 的题目列表Same N-ary Tree Comparison
类型:qbank
Decide whether two N-ary trees are identical in structure and values. The recursive solution is quick; the bar raiser's follow-up asks for an iterative version.
Requirements
Given the roots of two N-ary trees, determine whether they are identical — same structure and same node values.
A recursive solution compares the two roots, then pairwise compares their children lists in order.
Follow-up: provide an iterative version using an explicit stack or queue that walks both trees in lockstep.
Notes
Generalisation of LeetCode 100 ("Same Tree") to N-ary trees, where each node holds a list of children rather than fixed left/right.
Asked as the bar-raiser coding question. The recursive version is fast; the discriminating follow-up is converting it to an iterative traversal, so rehearse the stack-based lockstep walk.