[Leetcode] Length of Last Word
2012-12-04 03:56
441 查看
class Solution { public: int lengthOfLastWord(const char *s) { // Start typing your C/C++ solution below // DO NOT write int main() function int length = strlen(s); if (length == 0) return 0; int i = length - 1; while (s[i] == ' ') --i; if (i < 0) return 0; int count = 0; while (s[i] != ' ' && i >= 0) { ++count; --i; } return count; } };
相关文章推荐
- leetcode 58 Length of Last Word C++
- Leetcode-length-of-last-word
- LeetCode 57 Length of Last Word
- Leetcode Length of Last Word
- leetcode[58]Length of Last Word
- LeetCode 58 - Length of Last Word
- LeetCode: Length of Last Word
- leetcode-58 Length of Last Word
- LeetCode:Length of Last Word
- LeetCode_Length of Last Word
- [LeetCode刷题记录]Length of Last Word
- Leetcode: Length of Last Word
- leetcode--Length of Last Word
- LeetCode-lengthOfLastWord
- LeetCode-Length of Last Word
- LeetCode: Length of Last Word
- LeetCode--Length Of Last Word
- LeetCode 58 Length of Last Word
- leetcode:字符串之Length of Last Word
- LeetCode--No.58--Length of Last Word