58. Length of Last Word

Easy

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.

Example:

Input: "Hello World"
Output: 5
package leetcode.easy;

public class LengthOfLastWord {
@org.junit.Test
public void test() {
System.out.println(lengthOfLastWord("Hello World"));
} public int lengthOfLastWord(String s) {
String str = s.trim();
String[] buff = str.split(" ");
return buff[buff.length - 1].length();
}
}

LeetCode_58. 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 ...

随机推荐

  1. Spring Boot起步依赖:定制starter

    在定制我们自己的起步依赖--xxx.spring.boot.starter之前,我们先了解下什么是Spring Boot起步依赖. 起步依赖,是Spring Boot带给我们的一项重要的便利.要理解S ...

  2. 实验十一 团队作业7:团队项目设计完善&编码1

    博文简要信息表: 项目 内容 软件工程 https://www.cnblogs.com/nwnu-daizh/ 本次实验链接地址 https://www.cnblogs.com/nwnu-daizh/ ...

  3. 神经网络(2)---neurons and the brain

    神经网络是一个历史悠久的课题,当初提出是为了让机器能够模仿人的大脑一样工作.现在神经网络在处理很多机器学习的问题上发挥了很重要的作用. 神经网络的背景(我们可以利用神经网络做些什么) 大脑可以处理视觉 ...

  4. IE下iframe不能正常加载,显示空白

    下午帮忙看了一个web问题,index.html中嵌入<iframe>来加载同文件目录下的一个页面,在多个浏览器下测试,发现IE浏览器中会出现问题,<iframe>不能正常加载 ...

  5. 好用的Google Chrome插件

    juejin掘金 帮助我们随时了解Github上热门的项目,保证技术思想不掉队. Momentum 专注.待办清单…… Octotree Octotree 可以让我们在 Github 上浏览代码更加方 ...

  6. luogu 3919

    主席树 #include <iostream> #include <cstdio> #include <algorithm> #include <cmath& ...

  7. python中的关键字yield有什么作用?

    保存当前运行状态,然后暂停执行,即将函数挂起.yield关键字后面表达式的值作为返回值返回.当使用next(),send()函数从断点处继续执行.

  8. [bzoj 3534][Sdoi2014] 重建

    传送门 Description  T国有N个城市,用若干双向道路连接.一对城市之间至多存在一条道路. 在一次洪水之后,一些道路受损无法通行.虽然已经有人开始调查道路的损毁情况,但直到现在几乎没有消息传 ...

  9. python3编程基础之一:注释模块和包

    1.注释 python中的注释和其他任何编程语言中的注释都不一样,有的注释有特殊要求,而是还是有用的. 1).单行注释:注释以#开始到语句结尾,#号后一般跟一个空格 2).多行注释:文档注释,以&qu ...

  10. JAVA基础知识|synchronized和lock

    一.synchronized 是jvm的一个关键字,使用过程均由jvm控制 有三种使用方式: 修饰实例方法,作用于当前实例加锁,进入同步代码前要获得当前实例的锁 修饰代码块,同方法 修饰静态方法,作用 ...