LeetCode Length of Last Word really very easy
class Solution {
public:
int lengthOfLastWord(string s) {
int l=s.size();
int cnt=0;
int j=l-1;
while(j>=0 && s[j]==' ')
j--;
while(j>=0 && s[j]!=' '){
cnt++;
j--;
}
return cnt;
}
};
No comments:
Post a Comment