What's the meaning of this "Wrong Answer Error"?


  • 0
    T

    hi, I got an error in 1st test case with my Java code, the error is:
    Input: "a"
    Output: "a"
    Expected: "a"
    does anybody can help to explain it?
    My Java code is below:

    private int min(int a, int b){
        return a<b ? a : b;
    }
    public String maxPalindrome(String S){
        if(S == null || S.length()==0)    return new String();
        int n = S.length();
        char[] pMix = new char[2*n+1];
        pMix[0] = '#';
        for(int i=0, k=1;i<n || k<2*n+1; k++){
            if(pMix[k-1]=='#')    pMix[k] = S.charAt(i++);
            else                  pMix[k] = '#';
        }
        int[] p = new int[2*n+1];
        p[0] = 1;
        int id=0, mx=id+p[id];
        for(int i=1;i<2*n+1;i++){
            if(mx > i)      p[i] = min(p[2*id-i], mx-i);
            else            p[i] = 1;
            while(i-p[i]>=0 && i+p[i]<2*n+1 && pMix[i-p[i]]==pMix[i+p[i]])
                p[i]++;
            if(p[i] > p[id]){
                id = i;
                mx = i+p[i];
            }
        }
        char[] res = new char[2*p[id]];
        int k=0;
        for(int i=id-p[id]+1;i<id+p[id];i++){
            if(pMix[i]=='#')    continue;
            res[k++] = pMix[i];
        }
        return new String(res);        
    }

  • 0
    C

    Check the length() of your output. It might include some invisible charater


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.