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 ; int len = s.length();
int i = len - ;
int lastLen = ; // 去掉空格
while(s[i] == ' ' && i>=){
--i;
}//while
while(i >= && s[i] != ' '){
++lastLen;
--i;
}//while
return lastLen;
}
};

58. Length of Last Word (String)的更多相关文章

  1. LeetCode练题——58. Length of Last Word

    1.题目 58. Length of Last Word——Easy Given a string s consists of upper/lower-case alphabets and empty ...

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

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

  3. LeetCode 58. Length of Last Word

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

  4. 【LeetCode】58 - Length of Last Word

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

  5. 58. Length of Last Word

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

  6. Java [Leetcode 58]Length of Last Word

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

  7. 58. Length of Last Word【leetcode】

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

  8. <LeetCode OJ> 58. Length of Last Word

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

  9. 58. Length of Last Word(easy, 字符串问题)

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

随机推荐

  1. Asp.Net前台调用后台变量

    1.Asp.Net中几种相似的标记符号: < %=...%>< %#... %>< % %>< %@ %>解释及用法 答: < %#... %&g ...

  2. Activity服务类-9 TaskService服务类

    一共72个接口 1.创建任务(2个方法)//创建与任何流程实例无关的新任务.Task newTask();//使用用户定义的任务id创建一个新任务.Task newTask(String taskId ...

  3. 【JEECG技术文档】JEECG online 表单填值规则使用说明

    1. 功能介绍 JEECG online规则值自动生成功能 为实现online表单数据初始化功能. 为实现图中红框字段初始化功能,需要完成下面4步操作: 1)编写规则实现类 2) 配置填值规则 3)o ...

  4. day11-mysql中的mysql数据库不见了

    mysql中的mysql数据库不见了 昨天刚刚在vmware虚拟机的linux上安装mysql,今天登上就发现一个问题.通过网上漫长的寻找,终于解决了.所以我在这把我解决的步骤跟大家分享一下. 问题就 ...

  5. position: relative;导致页面卡顿

    1.现象: vue单页面项目 只有在某个页面切换的时候出现页面卡顿现象 经过长时间排查 确定最终原因是 该模块外层div使用  position: relative 根本原因:待完善

  6. 用Hadoop AVRO进行大量小文件的处理(转)

    使用 使用使用 使用 HDFS 保存大量小文件的缺点:1.Hadoop NameNode 在内存中保存所有文件的“元信息”数据.据统计,每一个文件需要消耗 NameNode600 字节内存.如果需要保 ...

  7. CocosCreator 自定义TypeScript在VsCode的提示数据

    在assets文件夹外新建xx.d.ts文件如:global.d.ts global.d.ts declare class UserData{ node:cc.Node; name:string; } ...

  8. HTML 样式兼容不同设备类型

    在项目中遇到在屏幕上显示的效果和打印时显示的效果不同,可以使用media属性来指定用于不同的媒介时使用的样式. media属性值: 值 描述 screen 计算机屏幕显示(默认) tty 电传打字机以 ...

  9. 升级nodejs的方法(3)

    第一种 找到 目录 删除 再重装 第二种 安装模块n n stable 第三种 nvm https://blog.csdn.net/weibo392/article/details/77368550 ...

  10. SQL Server Assembly (SQL CLR) 还原数据库后的问题

    最近弄项目迁移的时候遇到还原数据库(SQL Server 2008)后遇到的一个问题: 消息 10314,级别 16,状态 11,第 1 行 在尝试加载程序集 ID 65536 时 Microsoft ...