36 / 75
E

Same Tree

#36
treedfsbfs+1

Recursively check if two trees have identical structure and node values.

Example:

Input:p=[1,2,3], q=[1,2,3]
Output:true

Common Mistakes:

  • Not handling null cases properly (both null vs one null)
  • Checking structure without checking values
  • Using && instead of proper null checks (causes NPE)
  • Overcomplicating with iterative approach

Notes:

Simple recursive comparison. Time O(min(n,m)), Space O(min(h1,h2)) for recursion.

36/75
Same Tree