bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 100. Same Tree

100. Same Tree

Leetcode Solutions

Approach: Recursion

  1. Check if both nodes p and q are None. If they are, return True as both trees are empty.
  2. If one of the nodes is None and the other is not, return False as the trees are structurally different.
  3. If the values of p and q are different, return False.
  4. Recursively call the function on the left children of p and q.
  5. Recursively call the function on the right children of p and q.
  6. Return True if both recursive calls are True, otherwise return False.
UML Thumbnail

Approach: Iteration using Queue

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...