class Solution {
public: int lengthOfLastWord(string s) {
int i=;
int len=; while(s[i]&&s[i]==' ') i++; //去掉开头的空格
bool flag = false; while(s[i]){
cout<<len<<endl;
if(s[i]!=' '){
if(flag == true) //如果要计算下一个word,那么len=1
{len=;flag=false;}
else //如果还是当前word,len++
len++;
}
else flag=true; //是空格表示接下来,要统计的另外一个word了
i++;
} return len;
}
};

Length of Last Word的更多相关文章

  1. [LeetCode] Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  2. 【leetcode】Length of Last Word

    题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...

  3. [LeetCode] Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  4. [LintCode] Length of Last Word 求末尾单词的长度

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  5. Java for LeetCode 058 Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  6. LeetCode 58. Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  7. 【Length of Last Word】cpp

    题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...

  8. 【LeetCode】58 - Length of Last Word

    Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...

  9. Leetcode: Length of Last Word in python

    Length of Last Word Total Accepted: 47690 Total Submissions: 168587     Given a string s consists of ...

  10. leetcode 题解: Length of Last Word

    leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ...

随机推荐

  1. diff命令和patch命令

    diff命令和patch命令 Linux就这个范儿 2.9.5 文件对比命令——diff diff命令搭建网站离不开数据库,在Linux系统上我们使用源码安装了MySQL服务器.不久我们发现 Goog ...

  2. php 表单提交

    <?php header("Content-Type:text/html; charset=utf8"); class config{ public static funct ...

  3. Nginx负载均衡和LVS负载均衡的比较分析

    LVS和Nginx都可以用作多机负载的方案,它们各有优缺,在生产环境中需要好好分析实际情况并加以利用. 首先提醒,做技术切不可人云亦云,我云即你云:同时也不可太趋向保守,过于相信旧有方式而等别人来帮你 ...

  4. python模块(sys)

    SYS模块 sys.argv # 命令行参数List,第一个元素是程序本身路径 sys.exit(n) # 退出程序,正常退出时exit(0) sys.version # 获取Python解释程序的版 ...

  5. 怎样搭建本地svn服务器环境-轻松掌握版本管理

    版本管理一直是程序员使用频率比较高的一个工具软件.不管你是自己使用还是提供给别人使用,svn服务器的架设是一个入门功课.今天我们先来介绍一下怎么样在本地搭建svn服务器.这种应用一般是网络不是很好,提 ...

  6. mongodb的基本操作与插入文档(document)

    一.mongodb的基本操作: 1.查看mongodb当前所有的databases : show dbs 2.选择数据库(database) : use databaseName(该数据库不存在则会自 ...

  7. Troubleshooting JDK

    收集整理下JDK自带的关于 Troubleshooting 的文档 Java 2 Platform, Standard Edition 5.0 Troubleshooting and Diagnost ...

  8. IntelliJ IDEA 下的版本控制介绍

    不管是个人开发或是团队开发,版本控制都是可以很好地被使用的,目前我找不到任何开发者不使用版本控制的理由.而且对于 IDE 来讲,集成版本控制的本身就是它最大的亮点之一,很多开发者也是为此而使用它. 在 ...

  9. HTML语言的一些元素(四)

    以下资料整理自网路 1.锚点是网页制作中超级链接的一种,又叫命名锚记.命名锚记像一个迅速定位器一样是一种页面内的超级链接,运用相当普遍. 英文名:anchor 使用命名锚记可以在文档中设置标记,这些标 ...

  10. zabbix监控windows主机网卡流量

    监控windows主机网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.     欢迎加入:高级运维工程师之路 598432640 客户端配置:(172.30.1.120,wi ...