public boolean compareTrees(TreeNode tree1, TreeNode tree2) {
        if (tree1 == null && tree2 == null) return true;
        if (tree1 == null) return false; //tree2 will not be null in this situation
        if (tree2 == null) return false;
        return compareTrees(tree1.left, tree2.left) && compareTrees(tree1.right, tree2.right) && (tree1.val == tree2.val);
    }