Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

113. Same Tree

EasyDay 34 of 60Trees & BST

Given the roots p and q of two binary trees, return true if the trees are identical: they have exactly the same shape and every pair of matching nodes holds the same value.

Example 1
Input: p = [1,2,3], q = [1,2,3]
Output: true
Example 2
Input: p = [1,2], q = [1,null,2]
Output: false
Same values, but 2 is a left child in one tree and a right child in the other.
Constraints
  • Each tree has 0 to 100 nodes
  • -10^4 <= Node.val <= 10^4
Hints
Frequently asked at: Amazon, Microsoft, Bloomberg
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min