O(n) without calling isPalindrom() twice


#1
int Solution::solve(string A) {
    int left = 0;
    int right = A.size()-1;
    int count = 0;
    while(left<right)
    {
        if(A[left]==A[right]){left++;right--;}
        else if(A[left+1]==A[right]){count++;left++;}
        else if(A[left]==A[right-1]){count++;right--;}
        else return 0;
    }
    if(count == 0 and left == right) return 1;
    if(count == 1) return 1;
    return 0;
}