public class Solution {
    /**
     * 
     * @param p TreeNode类 
     * @param q TreeNode类 
     * @return bool布尔型
     */
    public boolean isSameTree (TreeNode p, TreeNode 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);
    }
}