[LeetCode58] Length of Last Word
题目:
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
分类:String
代码:
1 class Solution { 2 public: 3 int lengthOfLastWord(string s) { 4 string word; 5 string res; 6 stringstream ss(s); 7 while(!ss.eof()) 8 { 9 ss >> word; 10 res = word; 11 } 12 if(res.empty()) 13 return 0; 14 else 15 return res.size(); 16 } 17 };

浙公网安备 33010602011771号