3ms simple code in C


  • 0
    X

    int lengthOfLastWord(char* s) {
    int i = 0, re = 0,sum=0;
    for (i = 0; s[i] != NULL; i++) {
    if(s[i]==' '){
    sum=0;
    }else{
    sum++;
    }
    if(sum>0){
    re=sum;
    }
    }
    return re;
    }

    === === === === === === === === === === === === === === === === === === ===
    if you got any idea about my code please tell me.


Log in to reply
 

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