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. 17 webpack中babel的配置——静态属性与实例属性

    // class关键字,是ES6中提供的新语法,是用来实现ES6中面向对象编程的方式 class Person{ // 使用static关键字,可以定义静态属性 // 所谓的静态属性,就是可以直接通过 ...

  2. redis 与 序列化

    概念 序列化:把对象转化为可传输的字节序列过程称为序列化. 反序列化:把字节序列还原为对象的过程称为反序列化. 为什么需要序列化 序列化最终的目的是为了对象可以跨平台存储,和进行网络传输.而我们进行跨 ...

  3. div 水平垂直居中

    css <style> .main{ background: #999999; width: 600px; height: 400px; position: absolute; top: ...

  4. 【安卓笔记】Android保持Session

    简介: Session的概念在Android开发中遇到概率还是比较少,之前遇到一个项目的登陆接口返回不是Token,而且自己需要和服务端保持是Session,虽然这种情景很少,但是有时候后端有这种要求 ...

  5. 什么是php面向对象及面向对象的三大特性

    什么是面向对象? 面向对象编程,也就是我们常说的OOP,其实是面向对象的一部分.面向对象一共有3个部分:面向对象分析(OOA).面向对象设计(OOD).面向对象编程(OOP).我们现在将要学习的就是面 ...

  6. MongoDB 集合与文档操作

    一.创建DB 1.查看DB >show dbs 2.创建DB >use mydb 3.查看当前DB >db 4.删除DB >use mydb >db.dropDataba ...

  7. 在jsp页面,如何让一个button具有submit的功能

    <input type=button value="提交" οnclick=submit()> <script language=javascript>fu ...

  8. 带你了解HTTP协议(二)

    同样的,本文篇幅也比较长,先来一张思维导图,带大家过一遍.   一图看完本文 一. 计算机网络体系结构分层   计算机网络体系结构分层   计算机网络体系结构分层 不难看出,TCP/IP 与 OSI ...

  9. 在win10环境下配置spark和scala

    在这里配置的是在命令行下运行spark的环境用来学习,最后结果如下,可运行简单的代码. 0.jdk.scala和spark的版本问题 有关版本如官网所示,我想要强调的是spark至今并不支持jdk11 ...

  10. Linux--系统调优

    建议看看:https://www.cnblogs.com/yinzhengjie/p/9994207.html 一.关闭swap交换分区 Linux swapoff命令用于关闭系统交换区(swap a ...