public boolean isSameTree(TreeNode p, TreeNode q) {

        if (p == null && q == null) {
            return true;
        } else if (p == null || q == null) {
            return false;
        }

        boolean isLeftSame = isSameTree(p.getLeft(), q.getLeft());
        boolean isRightSame = isSameTree(p.getRight(), q.getRight());

        return p.getVal() == q.getVal() && isLeftSame && isRightSame;
    }