Easy 13 Length of Last Word(58)
来源:互联网 发布:python 数组去除重复 编辑:程序博客网 时间:2024/06/15 02:52
Description
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.
Solution
统计最后一个单词的长度,简单的统计,遇见空格就重新统计。有一点要注意的是,当字符串末尾有空格时,需要保留上一次的长度统计。
class Solution {public: int lengthOfLastWord(string s) { int len=0; bool flag=true; for(int i=0;i<s.size();i++){ if(!isspace(s[i])){ if(!flag) len=0;//通过标记位的形式,如果在遇见非空格字符,才清除上次记录。 flag=true; len++; }else{ flag=false; } } return len; }};
0 0
- Easy 13 Length of Last Word(58)
- [Leetcode 58, easy] Length of Last Word
- 【LeetCode】(58)Length of Last Word(Easy)
- <LeetCode><Easy> 58 Length of Last Word
- Length of Last Word(easy)
- LeetCode-58-Length of Last Word(字符串)-Easy
- leetcode 058 Length of Last Word(难易度:Easy)
- leetcode 58. Length of Last Word(easy)
- 58. Length of Last Word [easy] (Python)
- 58Length of Last Word
- #58 Length of Last Word
- 58Length of Last Word
- [58]Length of Last Word
- 58Length of Last Word
- 58 Length of Last Word
- 58 - Length of Last Word
- [58] Length of Last Word
- 58 Length of Last Word
- Python之网络爬虫完全教程
- 基于百度的webuploder做上传功能
- SQL Server 游标的使用
- 用echarts画桑基图的简单示例
- win7+tensorflow+python3.5+gpu
- Easy 13 Length of Last Word(58)
- HTTP 协议详解
- R文件找不到,报红问题
- Android第三方数据库框架litePal使用
- 完整java开发中JDBC连接数据库代码和步骤
- Java创建WebService服务及客户端实现
- input 框取值
- rabbitMq 交换机介绍
- AJAX获取数据,EJS创建HTML模板的简单项目使用