O(N^2) time complexity with string even and odd


#1
string Solution::longestPalindrome(string A) {
    // int m=A.length(),m=n;

    int n=A.length();
    string s="";
    vector<int> ev(n,0),ov(n,1);
    for(int i=0;i<A.length();i++)
    {
        int ri=i+1,li=i-1,lo=0,le=0;
        while(A[li]==A[ri] && ri<n && li>=0)
        {
            lo+=2;
            li--;
            ri++;
        }
        ov[i]+=lo;
        
          ri=i+1,li=i;
        while(A[li]==A[ri] && ri<n && li>=0)
        {
            le+=2;
            li--;
            ri++;
        }
        ev[i]+=le;
     if(ev[i]>ov[i] && s.length()<ev[i] )
        {
            int k=ev[i]/2;
            s=A.substr(i-k+1,ev[i]);
            
        }
       if(ev[i]<ov[i] && s.length()<ov[i] )
        {
            int k=ov[i]/2;
            s=A.substr(i-k,ov[i]);
            
        }}
    return s;}