My O(1)place,O(N*M) c solution


  • 0
    F

    int lengthOfLongestSubstring(char *s) {
    int res=1;
    int flag=0;
    int i;
    int h=0,t=1;
    if(s[0]=='\0')return 0;
    while(s[t]!='\0'){
    for(i=h;i<t;i++){
    if(s[i]==s[t]){
    if (res<t-h)
    res=t-h;
    h=i+1;
    flag=1;
    break;
    }
    }
    if(s[t+1]=='\0'){
    if(flag==0){
    if(res<t-h+1)
    res=t-h+1;
    }
    }
    t++;
    flag=0;
    }
    return res;
    }


Log in to reply
 

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