Leetcode 58 Length of Last Word 字符串

时间:2023-03-08 19:27:20

找出最后一个词的长度

 class Solution {
public:
int lengthOfLastWord(string s) {
int a = , l = , b = ;
while((b = s.find(" ", a)) != string::npos){
if(b - a > ) l = b - a;
a = b + ;
}
if(a == s.size()) return l;
else return s.size() - a;
}
};