Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appearing word if we loop from left to right) in the string.

If the last word does not exist, return 0.

Note: A word is defined as a maximal substring consisting of non-space characters only.

Example:

Input: "Hello World"
Output: 5
class Solution {
public int lengthOfLastWord(String s) {
if (s == null || s.length() == 0) {
return 0;
}
String[] strArr = s.split("\\s+");
// for case " "
return strArr.length == 0 ? 0: strArr[strArr.length - 1].length();
}
}

[LC] 58. Length of Last Word的更多相关文章

  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. 58. Length of Last Word最后一个单词的长度

    [抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: "b a " 最后一位是空格,可能误 ...

  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. 【LeetCode】58 - Length of Last Word

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

  6. 58. Length of Last Word

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

  7. Java [Leetcode 58]Length of Last Word

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

  8. 58. Length of Last Word【leetcode】

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

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

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

随机推荐

  1. php对象: __clone, __toString, __call,__isset, __unset, __sleep, __wakeup,

    __clone: 克隆对象,自动完成操作   clone()  __toString:  return返回字符串  __call: 当调用不存在的函数时,自动执行该方法,并返回相关值 __isset: ...

  2. python画图嵌入html

    #-*- coding=utf-8 -*- import matplotlib import matplotlib.pyplot as plt from io import BytesIO impor ...

  3. 00java语法基础和课后实践

    一:运行代码,并分析结果 代码1: package reserve; public class Main { public static void main(String[] args) { Size ...

  4. share团队冲刺7

    团队冲刺第七天 昨天:加入activity的内容,和队友的代码进行整合实现部分按钮功能 今天:继续完善代码,完善其他页面的功能,对主页和发表页面进行开发 问题:无

  5. Android studio2.2 app:transformNative_libsWithStripDebugSymbolForDebug

    开始搜到的问题相关链接: http://blog.csdn.NET/doumingliangdendsc/article/details/52595317 https://www.oschina.ne ...

  6. UML-逻辑架构和包图-概述

    回顾前几章学习了用例模型,本章开始学习设计模型.

  7. Chrome使用频率最高的快捷键

    标签 ctrl+T 打开新标签  ——— ctrl+W 关闭标签 ctrl+shift+T 打开上衣个被关闭的标签 ctrl+tab 标签向右切换 —— ctrl+shift+tab 标签向左切换 c ...

  8. 微信小程序2048开发进度(二)

    对小程序首先进行游戏架构: 实现小程序的首页展示界面,初始化棋盘格,以及NEW GAME按钮,成绩展现.

  9. [Scoi2016]背单词(trie+贪心)

    题意:重新解释一下题意吧(题意晦涩难懂) 给定n个单词,你可以按照顺序学习,当学习这一单词时,这个单词是第x个要学习的单词,需要的代价分三类: 1.若存在其他单词是其后缀没被学习,则代价为n2 2.若 ...

  10. App 性能测试

    app常见性能测试点: https://blog.csdn.net/xiaomaoxiao336368/article/details/83547318