LeetCode 58 Length of Last Word
来源:互联网 发布:mac桌面文件路径 编辑:程序博客网 时间:2024/06/02 02:11
题意:
求一个一串字符中,最后一个单词的长度。
思路:
巨无聊一个题…… 从尾开始去掉空格,这时开始计数字母,直到串的头或者遇到空格为止。
代码:
class Solution {public: int lengthOfLastWord(string s) { int n = s.size(); if (n == 0) { return 0; } for (--n; n >= 0 && s[n] == ' '; --n); for (int i = n;; --i) { if (i < 0 || s[i] == ' ') { return n - i; } } return 0; }};
阅读全文
0 0
- [leetcode 58] Length of Last Word
- leetcode-58 Length of Last Word
- Leetcode NO.58 Length of Last Word
- LeetCode #58 length of Last Word
- [LeetCode 58]Length of Last Word
- leetcode || 58、Length of Last Word
- LeetCode 58 Length of Last Word
- [Leetcode 58, easy] Length of Last Word
- Length of Last Word (leetCode 58)
- leetcode[58]:Length of Last Word
- 【leetcode c++】58 Length of Last Word
- leetcode 58:Length of Last Word
- LeetCode---(58)Length of Last Word
- leetcode-58-Length of Last Word
- Leetcode# 58 Length of Last Word
- [leetcode-58]Length of Last Word(c)
- leetcode 58: Length of Last Word
- leetCode #58 Length of Last Word
- SourceTree安装与使用方法
- MATLAB
- Scala中apply方法以及函数返回有无unit的区别
- android 偏好保存数据
- 使用rails自带方法去除html标签
- LeetCode 58 Length of Last Word
- 差分约束——vijos1589
- iOS系统库头文件中NS_AVAILABLE和NS_DEPRECATED_IOS相关
- 自定义View练习
- yii2用gii生成crud为什么views找不到生成文件
- centos 6.5 和centos 7关于防火墙的命令
- 58 同城移动端 Passport SDK 的设计与技术细节
- 在Servlet中request.setCharacterEncoding() response.setCharacterEncoding() response.setContentType()区别
- 线程互斥(互斥量)及死锁形成