给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。

如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。

示例 1:

https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg

输入:p = [1,2,3], q = [1,2,3]
输出:true

示例 2:

https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg

输入:p = [1,2], q = [1,null,2]
输出:false

示例 3:

https://assets.leetcode.com/uploads/2020/12/20/ex3.jpg

输入:p = [1,2,1], q = [1,1,2]
输出:false
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isSameTree(TreeNode p, TreeNode q) {
        /*逃离条件不能添加p.val == q.val, 因为默认情况即p.val == q.val 
          逃离条件 判断 p.val == q.val 导致 root 节点直接返回true 
					并且下面的判断将skip
        */ 
        if( (p == null && q == null) ){
            return true;
        }
        if((p!=null && q == null) || (p == null && q!=null) || (p.val != q.val)){
            return false;
        }
        
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}