3ms C++ Solution


  • 0
    F
    int lengthOfLastWord(string s) {
         int count=0;
         for(int s_len=0; s[s_len]!='\0';s_len++){       
           if(s[s_len]==' ') continue; 
           if(s[s_len]!=' ' && s[s_len-1]==' ')
             count=0;             
           count++;
          }
          return count;
       }
    

Log in to reply
 

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