LeetCode/string/ValidPalindromeII.java
// Brute force solution -- Time Limit Exceeded
Brute force solution -- Time Limit Exceeded
Brute force solution -- Time Limit Exceeded
public boolean validPalindromeBruteFore(String s) {
        StringBuilder sb = new StringBuilder();
        sb.append(s);
        if (sb.toString().equalsIgnoreCase(sb.reverse().toString())) {
            return true;
        } else {
            for (int i = 0; i < s.length(); i++) {
                sb.setLength(0);
                sb.append(s);
                sb.deleteCharAt(i);
                if (sb.toString().equalsIgnoreCase(sb.reverse().toString())) {
                    return true;
                }
            }
        }
        return false;
    }
public boolean validPalindromeBruteFore ( String s ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( s ) ; if ( sb . toString ( ) . equalsIgnoreCase ( sb . reverse ( ) . toString ( ) ) ) { return true ; } else { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { sb . setLength ( 0 ) ; sb . append ( s ) ; sb . deleteCharAt ( i ) ; if ( sb . toString ( ) . equalsIgnoreCase ( sb . reverse ( ) . toString ( ) ) ) { return true ; } } } return false ; }
Brute force solution -- Time Limit Exceeded
Brute force solution -- Time Limit Exceeded
// sb.insert(i, 'a');