Can anyone help find the bug? Thanks a lot! When the input is "c", it says the output is 0 not 1.


  • 0
    L
    int lengthOfLongestSubstring(char* s) {
    char last[128]={-1};
    int index;
    int len=0;
    int max=0;
    int start=0;
    for(index=0;s[index];index++){
       if(last[s[index]]==-1){
           last[s[index]]=index;
           len=(index-start+1>len)?index-start+1:len;
       }
       else{
           start=(last[s[index]]+1>start)?last[s[index]]+1:start;
           len=(index-start>len)?index-start:len;
           last[s[index]]=index;
       }
    }
    return len;
    

    }


Log in to reply
 

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