Length of Last Word
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的更多相关文章
- [LeetCode] Length of Last Word 求末尾单词的长度
		Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ... 
- 【leetcode】Length of Last Word
		题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ... 
- [LeetCode] Length of Last Word
		Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ... 
- [LintCode] Length of Last Word 求末尾单词的长度
		Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ... 
- 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 ... 
- LeetCode 58. Length of Last Word
		Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ... 
- 【Length of Last Word】cpp
		题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ... 
- 【LeetCode】58 - Length of Last Word
		Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ... 
- Leetcode: Length of Last Word in python
		Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ... 
- leetcode 题解:  Length of Last Word
		leetcode: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', re ... 
随机推荐
- jni学习
			Java Native Interface (JNI)标准是java平台的一部分,它允许Java代码和其他语言写的代码进行交互.JNI 是本地编程接口,它使得在 Java 虚拟机(VM) 内部运行的 ... 
- 发送xml或json格式的数据给服务器
			后台通过context.Request.InputStream来接收 #region 发送消息 + void SendMessage() /// <summary> /// 发送消息 // ... 
- python_序列
			1. python存在6中内建序列:列表.元组.字符串.Unicode字符串.buffer对象.xrange对象 列表可以修改,元组和字符串不可以修改. 2. 序列支持的操作: 索引 序列中所有的元素 ... 
- [GeoServer]Openlayers简单调用
			Openlayers Demo: <html> <head> <title>OpenLayers Example</title> <script ... 
- Vue.2.0.5-Class 与 Style 绑定
			Class 与 Style 绑定 数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是属性 ,我们可以用v-bind 处理它们:只需要计算出表达式最终的字符串.不过,字符串拼 ... 
- ThinkPHP分页链接支持数组参数的办法
			这几天在用ThinkPHP做系统,搜索页有个数组参数提交 <input class="params_t" name="t[]" type="ch ... 
- linux bash history
			vim /etc/profile export HISTSIZE=10000 export HISTTIMEFORMAT="`whoami` : %F %T : " export ... 
- Java基础之集合框架——使用集合Vector<>挑选演员(TryVector)
			控制台程序. public class Person implements Comparable<Person> { // Constructor public Person(String ... 
- [翻译]java nio 概述
			原文地址:http://tutorials.jenkov.com/java-nio/overview.html java NIO 包含一下核心内容: Channels Buffers Selector ... 
- Java线程总结
			在java中要想实现多线程,有两种手段,一种是继续Thread类,另外一种是实现Runable接口. 对于直接继承Thread的类来说,代码大致框架是: class 类名 extends Thread ... 
