public boolean isValid(String str, int begin, int end) {
        // int begin = 0, end = str.length() - 1;
        while (begin < end) {
            if (str.charAt(begin) != str.charAt(end)) {
                return false;
            }
            ++begin;
            --end;
        }
        return true;
    }