Leet75 : Day 2 #100. Same Tree

Leet75 : Day 2 #100. Same Tree

Question: " Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

"

To solve the question you must be able to implement a tree and must have solved the challenge for day 1 which is to calculate the max dept of a tree

//javascript
var isSameTree = function(p, q) {

    if(p ==null &&  q ==null) return true
        if(p ==null ||  q ==null) return false

    if (p.val != q.val){
        return false
    }
   return isSameTree(p.left,q.left) &&
    isSameTree(p.right,q.right)

};

Link to Leetcode question