[LeetCode] 58. Length of Last Word
来源:互联网 发布:java葵花宝典2017 编辑:程序博客网 时间:2024/06/03 16:58
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.
Note: A word is defined as a character sequence consists of non-space characters only.
For example,
Given s = “Hello World”,
return 5.
class Solution {public: int lengthOfLastWord(string s) { while (!s.empty() && s.back() == ' ') s.pop_back(); int i = (int)s.size() - 1; while (i >= 0 && s[i] != ' ') i--; return (int)s.size() - i - 1; }};
阅读全文
0 0
- 58. Length of Last Word Leetcode Python
- [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
- <LeetCode OJ> 58. Length of Last Word
- 58. Length of Last Word LeetCode
- 【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
- 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-java-58. Length of Last Word
- Servlet 监听器----Session
- 机器学习-线性回归
- Linux 其他命令
- axis
- MYSQL存储过程循环遍历插入数据
- [LeetCode] 58. Length of Last Word
- Npm简介
- 读《人类简史》有感
- Google算法题:贪吃蛇
- 运动控制有哪些方法
- 解决 命名空间中不存在类型或命名空间名称“App_Code”(是否缺少程序集引用?)的问题
- maven在父级项目文件夹下创建子项目
- 1.初步启动树莓派
- 前端好用的插件