leetcode——58——Length of Last Word
来源:互联网 发布:广州管家婆软件 编辑:程序博客网 时间:2024/06/11 09:56
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) { if(s.empty()) return 0; int len = s.size(); int count = 0; while(s[len-1]==' ') len--; for(int i = len-1;i>=0;i--) { if(s[i]==' ') break; count++; } return count; }};
0 0
- LeetCode——Length of Last Word
- LeetCode——Length of Last Word
- leetcode——Length of Last Word
- LeetCode—Length of Last Word
- leetcode——58——Length of Last Word
- Leetcode Problem.58—Length of Last Word
- Python学习——leetcode(Length of Last Word)
- leetcode 058 —— Length of Last Word
- leetcode刷题日记—— Length of Last Word
- LeetCode 之 Length of Last Word — C 实现
- LeetCode58——Length of Last Word
- LeetCode58——Length of Last Word
- Algorithms—58.Length of Last Word
- LeetCode 58 — Length of Last Word(C++ Java Python)
- Leetcode刷题记——58. Length of Last Word(最后一个单词的长度)
- LeetCode刷题(C++)——Length of Last Word(Easy)
- [leetcode 58] Length of Last Word
- leetcode-58 Length of Last Word
- 4.6日 js call css classList js 拖拽 十个心得
- HTTP头的Expires与Cache-control
- 默认参数
- react native中使用react-native-viewpager实现的商品展示添加点击事件
- javaEE
- leetcode——58——Length of Last Word
- 杨辉三角的打印
- 第五周项目2-设计游戏角色类(2)
- IOS 开发-UI初级 (一)
- V4L2常用命令详解
- npm安装包失败
- js中++写在变量前后会有什么不同?
- 第五周项目3-时间类
- STM32入门之模板建立