文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
Length of Last Word2. Solution
class Solution {
public:
int lengthOfLastWord(string s) {
int length = 0;
int index = s.find_last_not_of(" ");
if(index == -1) {
return length;
}
while(index >= 0 && s[index--] != ' ') {
length++;
}
return length;
}
};
网友评论