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.

中文:给定一个字符串,包括大写/小写字母和空格字符,返回字符串中最后一个单词的长度。

假设最后一个单词不存在,返回0.

注意:一个单词被定义为仅包括非空字符的字符序列。

比如:

给定 s="Hello World",

返回 5.

此题可能是leetcode上面的最简单的一道题了。

Java:

	public int lengthOfLastWord(String s) {
if(s.trim().equals(""))
return 0;
String[] str = s.split("\\s+");
int len = str.length;
return str[len-1].length();
}

LeetCode——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 @ Python

    原题地址:https://oj.leetcode.com/problems/length-of-last-word/ 题意: Given a string s consists of upper/lo ...

  3. [LeetCode] Length of Last Word

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

  4. Leetcode: Length of Last Word in python

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

  5. [Leetcode] Length of last word 最后一个单词的长度

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

  6. [LeetCode] Length of Last Word 字符串查找

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

  7. LeetCode Length of Last Word 最后一个字的长度

    class Solution { public: int lengthOfLastWord(const char *s) { ; string snew=s; ,len=strlen(s); ]; ) ...

  8. leetcode 题解: Length of Last Word

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

  9. 【一天一道LeetCode】#58. Length of Last Word

    一天一道LeetCode系列 (一)题目 Given a string s consists of upper/lower-case alphabets and empty space charact ...

随机推荐

  1. JavaSE_ 网络编程 目录(26)

    JavaSE学习总结第26天_网络编程26.01 网络编程概述26.02 网络模型概述和图解26.03 网络编程三要素概述26.04 网络编程三要素之IP概述126.05 InetAddress类的概 ...

  2. Java "==和equals区别" 示例

    import java.util.Calendar; import java.util.Date; import java.util.Locale; public class test { publi ...

  3. Delphi中取整函数Round的Bug解决

    Delphi中 Round函数有个Bug一旦参数是形如 XXX.5这样的数时如果 XXX 是奇数 那么就会 Round up如果 XXX 是偶数 那么就会 Round down例如 Round(17. ...

  4. HDU 1348 Wall

    题解:计算凸包周长 #include <iostream> #include <cmath> #include <algorithm> const int size ...

  5. WPF 自定义TextBox

    1.TextBox前加图标. 效果: <TextBox Width="300" Height="30" Style="{StaticResour ...

  6. ActionScript3游戏中的图像编程(连载十七)

    总文件夹:http://blog.csdn.net/iloveas2014/article/details/38304477 1.3.3 HSB与RGB之间的互转公式及HSL和HSV对色彩属性理解的异 ...

  7. 不重新编译PHP文件的情况下php GD库扩展库的编译安装(centos)

    gd-2.0.33.tar.gz http://www.boutell.com/gd/ jpegsrc.v6b.tar.gz http://www.ijg.org/ libpng-1.2.7.tar. ...

  8. SQL执行效率总结

    1.关于SQL查询效率,100w数据,查询只要1秒,与您分享: 机器情况 p4: 2.4 内存: 1 G os: windows 2003 数据库: ms sql server 2000 目的: 查询 ...

  9. 【原】Spring和Dubbo整合案例和过程

    Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单的模 ...

  10. python之filter过滤器

    Python内建的filter()函数用于过滤序列. 和map()类似,filter()也接收一个函数和一个序列.和map()不同的时,filter()把传入的函数依次作用于每个元素,然后根据返回值是 ...