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

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    public boolean HasSubtree(TreeNode root1,TreeNode root2) {
        if (null == root2) {
            return false;
        }
        return process1(root1, root2);
    }
    
    public boolean process1(TreeNode node1, TreeNode node2) {
        if (null == node1) {
            return false;
        }
        if (process2(node1, node2)) {
            return true;
        }
        return process1(node1.left, node2) || process1(node1.right, node2);
    }
    
    public boolean process2(TreeNode node1, TreeNode node2) {
        if (null == node2) {
            return true;
        }
        if (null == node1) {
            return false;
        }
        if (node1.val != node2.val) {
            return false;
        }
        boolean lb = process2(node1.left, node2.left);
        boolean rb = process2(node1.right, node2.right);
        return lb && rb;
    }
}