leetcode58. Length of Last Word
来源:互联网 发布:自救手环 淘宝 编辑:程序博客网 时间:2024/06/07 02:19
不知为什么我的博客也会多了些关注,非常感谢能给你们提供到帮助。
让我坚持做的一点事情也有了点意义。
就是判断最后一个字符串的长度。
有一个坑就是最后一个可能为空格,所以要去掉最后的空格。
class Solution {public: int lengthOfLastWord(string s) { int n=s.size(); int ans=0; int i=n-1; while(s[i]==' ') i--; for(;i>=0;i--){ if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z') ans++; if(s[i]==' ') break; } return ans; }};
阅读全文
0 0
- LeetCode58:Length of Last Word
- Leetcode58 Length of Last Word
- LeetCode58----Length of Last Word
- leetcode58---Length of Last Word
- leetcode58:Length of last word
- Leetcode58: Length of Last Word
- leetcode58: Length of Last Word
- Leetcode58.Length of Last Word
- LeetCode58. Length of Last Word
- LeetCode58 Length of Last Word
- Leetcode58. Length of Last Word
- leetcode58. Length of Last Word
- leetcode58. Length of Last Word
- LeetCode58. Length of Last Word
- Leetcode58-Length of Last Word
- LeetCode58——Length of Last Word
- LeetCode58——Length of Last Word
- Length of Last Word
- zlib压缩库解压失败的问题
- 关于CGI
- CodeForces 526F Pudding Monsters (分治)
- IDEA的常用操作(快捷键)
- 使用C/C++输出各种进制
- leetcode58. Length of Last Word
- 自定义网络请求
- hdu1411求四面体体积
- iOS 移动端架构的那些事
- Oracle集群
- Handler AsyncTask
- 深度学习的一个有意思的应用: 通过一张图片讲故事
- 创建以点开头的文件或文件夹
- CSS3 2D平移,旋转,缩放,倾斜