import java.util.*;

/*
 * public class TreeNode {
 *   int val = 0;
 *   TreeNode left = null;
 *   TreeNode right = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param p TreeNode类 
     * @param q TreeNode类 
     * @return bool布尔型
     */
    public boolean isSameTree (TreeNode p, TreeNode q) {
        // write code here
        if(p == null && q == null) return true;
        if(p == null || q == null) return false;
        if(p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right)){
            return true;
        }else{
            return false;
        }
    }
}