int lengthOfLastWord(const char *s) {//Length of Last Word
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(!s) return 0;
int lastlen=0;
int currentlen=0;
while(*s)
{
if(*s==' ')
{
if(currentlen!=0)
{
lastlen=currentlen;
}
currentlen=0;
}
else
{
currentlen++;
}
s++;
}
if(currentlen!=0)
{
lastlen=currentlen;
}
return lastlen;
}
leetcode:Length of Last Word
最新推荐文章于 2019-06-20 10:49:28 发布