题目:
题解:
class Solution {
public:int lengthOfLastWord(string s) {int index = s.size() - 1;while (s[index] == ' ') {index--;}int wordLength = 0;while (index >= 0 && s[index] != ' ') {wordLength++;index--;}return wordLength;}
};
题目:
题解:
class Solution {
public:int lengthOfLastWord(string s) {int index = s.size() - 1;while (s[index] == ' ') {index--;}int wordLength = 0;while (index >= 0 && s[index] != ' ') {wordLength++;index--;}return wordLength;}
};