Need to know the reason for WA (brute force)

interview-questions
programming
Tags: #<Tag:0x00007f2425ef0c18> #<Tag:0x00007f2425ef0a88>

#1
bool isPalindrome(string s){
    int l=s.size();
    for(int i=0, j=l-1; i<=j; i++, j--){
        if(s[i]!=s[j]) return false;
    }
    return true;
}

string Solution::longestPalindrome(string A){
    string s1=A, s2=A;
    int flag1=0, flag2=0;
    for(int i=0; i<s1.size(); i++){
        if(isPalindrome(s1)){
            int flag1=1;
            break;
        }
        s1.erase(s1.begin());
    }
    for(int i=s2.size()-1; i>=0; i--){
        if(isPalindrome(s2)){
            int flag2=1;
            break;
        }
        s2.erase(s2.begin()+s2.size()-1);
    }
    if(s1.size()>s2.size()) return s1;
    else return s2;
}