572. Subtree of Another Tree

Practice Subtree of Another Tree for free on NudgeCode: Easy, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return true if some node of root has a subtree identical to subRoot (same shape and same values). The subtree of a node is that node together with all of its descendants, so the whole of root also counts.

Example

root = [3,4,5,1,2], subRoot = [4,1,2]  ->  true

Constraints