LeetCode 58. Length of Last Word
Solution1:我的答案
唯一的遗憾不是一遍过啊!哈哈哈~
class Solution {
public:
int lengthOfLastWord(string s) {
int length = 0;
s.erase(0, s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
if (!s.size()) return length;
return s.substr(s.find_last_of(" ") + 1).size();
}
};