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
- 1 <= number of nodes in root <= 2000
- 1 <= number of nodes in subRoot <= 1000
- -10^4 <= Node.val <= 10^4