/**
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(root1 == null || root2 == null) {
            return false;
        }
        if(root1.val == root2.val) {
            if(root2.left == null) {
                if(root2.right == null) {
                    return true;
                } else {
                    if(HasSubtree(root1.right, root2.right))
                        return true;
                }
            } else {
                if(root2.right == null) {
                    if(HasSubtree(root1.left, root2.left))
                        return true;
                } else {
                    if(HasSubtree(root1.left, root2.left) && HasSubtree(root1.right, root2.right))
                        return true;
                }
            }
        }
        return HasSubtree(root1.left, root2) || HasSubtree(root1.right, root2);
    }
}