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. 使用 ajax 多次请求,并将结果集合并(ajax 非异步)

    直接上代码吧... 里面有注释 <!DOCTYPE html> <html> <head> <meta charset="utf-8" / ...

  2. 你所不知道的printf函数

    #include <stdio.h> int main(void) { int a = 4; int b = 3; int c = a / b; float d = *(float *)( ...

  3. 如何在C中以二进制格式打印十进制数?

    回答: #define CHAR_BITS  8  // size of character #define INT_BITS  ( sizeof(int) * CHAR_BITS) //bits i ...

  4. [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]

    https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...

  5. LeetCode 273. Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/description/ 题目: Convert a non-negati ...

  6. php数据类型之查看和判断数据类型

    我们知道了一个数据的类型,才能进行下一步操作.后面的时候,大家可以学习到更多的知识——自定义功能(函数). 我们来做一个场景模拟:(注:眼前不用会写这个函数,以后会教大家) 假设,我们可以写一个智能的 ...

  7. linux系列(二十四):du命令

    1.命令格式 du [选项][文件] 2.命令功能 显示每个文件和目录的磁盘使用空间. 3.命令参数 -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文件大小时,以byte为 ...

  8. vue学习--vue项目端口不固定,无法指定问题

    写于20190819 前面是自己解决的思路,后面是解决方法以及需要记住的一些更改 package.json 之前只知道vue项目是基于node.js,对node.js了解不是很深入,项目的开始文件是p ...

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

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

  10. javaSE集合---进度2

    一.集合框架 1.特点 对象封装数据,对象多了也需要存储,集合用于存储对象. 对象的个数确定可以使用数组,但是不确定的话,可以用集合,因为集合是可变长度的. 2.集合和数组的区别 数组是固定长度的,集 ...