Subtree of Another Tree
Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

30:00

Subtree of Another Tree
easy
Topics
Companies

Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.

Example 1:
Input: {"root":[3,4,5,1,2],"subRoot":[4,1,2]}
Output: true
Constraints:
  • The number of nodes in root is in the range [1,2000][1, 2000].

  • The number of nodes in subRoot is in the range [1,1000][1, 1000].

  • 104root.val,subRoot.val104-10^4 \leq \text{root.val}, \text{subRoot.val} \leq 10^4

Input
arr ={"root":[3,4,5,1,2],"subRoot":[4,1,2]}

3

4

5

1

2

4

1

2

Variables
No variables to display
DepthFunction Call
Stack empty
0/4