100 Same Tree

/**
 *题意:判断两棵二叉树 
 * 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}
 */
var isSameTree = function(p, q) {
    if(p == null && q == null) return true;
    if(p && q == null) return false;
    if(p == null && q) return false;
    if(p.val != q.val) return false;

    return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
};

  

posted @ 2015-10-04 20:56  calmound  阅读(217)  评论(0编辑  收藏  举报