Same Tree | LeetCode 100

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard

/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
let isSameTree = function(p, q) {
    if (p === null || q === null) {
        return p === q;
    }
    
    if (p.val !== q.val) {
        return false;
    }
    
    return isSameTree(p.right, q.right) && isSameTree(p.left, q.left);
};