[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 ...
随机推荐
- Bugku杂项(1—28)
1.签到题 只要关注公众号就可以得到 flag---开胃菜 2.这是一张单纯的图片 用Winhex打开,会发现最下面有一行编码: key{you are right} 是一串HTML编码,解密下就行了 ...
- selenium破解人人登陆验证码
from selenium import webdriverfrom PIL import Imagefrom chaojiying import Chaojiying_Clientimport ti ...
- App的工程框架
对于我刚下载的Android studio,来说一说它的框架结构 Project项目结构: .gradle:Gradle编译系统,版本由wrapper指定 .idea:IDE所需要的文件 .app: ...
- JS用例
showBtn :class="{getInput:showBtn}"v-if="showBtn" showBtn: true, this.showBtn = ...
- h5-携程页面小案例-伸缩盒子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java 面向对象概述原理: 多态、Object类,转型(8)
Java 面向对象概述原理: 多态.Object类,转型(8) http://docs.oracle.com/javase/tutorial/java/IandI/override.html Java ...
- 基因调控网络 (Gene Regulatory Network) 01
本文为入门级的基因调控网络文章,主要介绍一些基本概念及常见的GRN模型. 概念:基因调控网络 (Gene Regulatory Network, GRN),简称调控网络,指细胞内或一个基因组内基因和基 ...
- liunx 常用操作(自用)
Centos7解压文件 tar -zxvf 文件名[test.tar.gz] Centos7安装vim yum -y install vim* Centos7安装ifconfig yum instal ...
- 吴裕雄--天生自然GPU配置:查看本机显卡是否支持GPU
NVIDIA的GF8级别以上的显卡才能支持physx物理加速(即GPU加速),ATI的显卡不支持. 打开:设备管理器,点击:显示适配器
- Java--平台版本、跨平台、JVM、JDK、JRE
Java2平台版本 Java2平台包括标准版(J2SE).企业版(J2EE)和微缩版(J2ME)三个版本 J2SE 包含那些构成Java语言核心的类. J2EE 包含J2SE 中的类,并且还包含用于开 ...