[LC] 58. Length of Last Word
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的更多相关文章
- 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 ...
- 58. Length of Last Word最后一个单词的长度
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: "b a " 最后一位是空格,可能误 ...
- [LeetCode] 58. Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- LeetCode 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【LeetCode】58 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 58. Length of Last Word
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- Java [Leetcode 58]Length of Last Word
题目描述: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...
- 58. Length of Last Word【leetcode】
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- <LeetCode OJ> 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
随机推荐
- 远程桌面,出现身份验证错误,要求的函数不正确,这可能是由于CredSSP加密Oracle修正
问题点: 升级至win10 最新版本10.0.17134,安装最新补丁后无法远程win server 2016服务器,报错信息如下: 出现身份验证错误,要求的函数不正确,这可能是由于CredSSP加密 ...
- spark与Scala版本对应问题
在阅读一些博客和资料中,发现安装spark与Scala是要严格遵守两者的版本对应关系,如果版本不对应会在之后的使用中出现许多问题. 在安装时,我们可以在spark的官网中查到对应的Scala版本号,如 ...
- {转}理解HTTP/304响应
源文(英):http://www.telerik.com/blogs/understanding-http-304-responses 中文译文:http://www.cnblogs.com/ziyu ...
- 吴裕雄--天生自然 PHP开发学习:Switch 语句
<?php $favcolor="red"; switch ($favcolor) { case "red": echo "你喜欢的颜色是红色! ...
- 苹果智能AR挡风玻璃靠谱吗?
在过去十年,外界给苹果的形象一直是"伟大的硬件公司",他们的产品在外观方面往往比内涵更加引人注目,兼具娱乐性和艺术性, iPhone/iPad/iPod莫不如此,所以,当坊间传闻苹 ...
- XML技术详解
XML 1.XML概述 XML可扩展标记语言是一种基于文本的语言用作应用程序之间的通信模式,是一个非常有用的描述结构化信息的技术.XML工具使得转化和处理数据变得十分容易,但同样也要领域相关的标准和代 ...
- Linux&Win双系统下时间显示不正常的问题
于近期开始研究Linux,目前用的是ubuntu.本想着用Linux搞事情,没想到却被Linux搞了. 我安装的是双系统,Linux&windows的组合.相信刚开始用双系统的小伙伴们一定会碰 ...
- Python说文解字_杂谈03
1. 我们从前面的知识得到,所有的类都要继承自object这个基类(超类),另外我们知道“继承”可以继承类的属性和方法.我们起始通过type创建类的时候,自然而然的也会从ojbect继承他的一些属性和 ...
- MySQL之完整建表语句及数据类型
1.创建表的完整语法 create table 表名( 字段名称 数据类型[(长度) 约束条件], 字段名称 数据类型[(长度) 约束条件] ) 必须的:字段名 数据类型 表名 可选的:长度 约束条件 ...
- uwsgi Import Error: No module named 'encodings'
https://serverfault.com/questions/558427/uwsgi-import-error-no-module-named-encodings I don't know i ...