Why my solution code get a different result in this online check system?


  • 0
    M

    My code is :
    class Solution
    {
    public:
    int lengthOfLongestSubstring( string s)
    {
    int CharIndex[256] ;
    int maxLength = 0;
    int start = 0;
    const char * p = s.data();
    memset(CharIndex, -1, 256);
    int i = 0;
    for( ; i < s.length(); i++)
    {
    if( (start <= CharIndex[p[i]]) && (CharIndex[p[i]] < i))
    {
    maxLength = maxLength>(i-start)?maxLength:(i-start);
    start = CharIndex[p[i]] + 1;
    }
    CharIndex[p[i]] = i ;
    }
    maxLength = maxLength>(i-1-start)?maxLength:(i-1-start);
    return maxLength;
    }
    };

    when judging in this online system, the test input as
    "hnwnkuewhsqmgbbuqcljjivswmdkqtbxixmvtrrbljptnsnfwzqfjmafadrrwsofsbcnuvqhffbsaqxwpqcac"

    this online system tell me the output is 11, but 12 is expected.

    But in my local machine, suse 10 with gcc 4.1.2, the output for this input is 12, what is wrong with it ?


Log in to reply
 

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