v9.1.1
Menu

Same Tree

easyFREETreesBlind 75

Given two binary trees (level-order arrays), check if they are structurally identical with the same node values.

Example

Input
1,2,3
1,2,3
Output
True
Reasoning
  • The two input arrays 1,2,3 and 1,2,3 represent two binary trees in level-order traversal.
  • We compare the two arrays node by node: both have the same root node value 1, the same left child node value 2, and the same right child node value 3.
  • Since the arrays have the same length and all corresponding node values match, we conclude that the two binary trees are structurally identical with the same node values.
  • The function returns True, indicating that the two input trees are the same.

Constraints

  • 0 <= number of nodes <= 100
  • -10^4 <= Node.val <= 10^4

More from Blind 75

solution.py

Test results

Sign in to run your code against the test cases.