Length of Last Word
来源:互联网 发布:pdf福昕阅读器 mac 编辑:程序博客网 时间:2024/05/16 07:48
理解了题意以后就很简单了。
class Solution {public: int lengthOfLastWord(const char *s) { if (s == NULL) return 0; int n = strlen(s); int p = n - 1; while (p >= 0) { if (s[p] == ' ') --p; else break; } if (p == -1) return 0; int last = p; while (p >= 0) { if (!isAlpha(s[p])) break; --p; } return last - p; } bool isAlpha(char c) { if (c >= 'a' && c <= 'z') return true; if (c >= 'A' && c <= 'Z') return true; return false; }};
http://oj.leetcode.com/problems/length-of-last-word/
0 0
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- LeetCode | Word Break II
- Android IPC 通讯机制源码分析
- 数组的定义
- HTML Basic II
- 十三章 上课内容
- Length of Last Word
- 英语6级复习资料2
- noip2005解题报告
- 1602总结
- NSString写入文件
- 周鸿祎--怎样才能成为一个优秀的产品经理(2)?
- Android的MediaPlayer架构介绍
- (16)万能查询还是万恶查询?
- c++中cin、cin.get()、cin.getline()、getline()、gets()等函数的运用