LeetCode_58. Length of Last Word
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 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的更多相关文章
- [LeetCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【leetcode】Length of Last Word
题目简述 Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return ...
- [LeetCode] Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- [LintCode] Length of Last Word 求末尾单词的长度
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 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 ...
- LeetCode 58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- 【Length of Last Word】cpp
题目: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return t ...
- 【LeetCode】58 - Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- Leetcode: Length of Last Word in python
Length of Last Word Total Accepted: 47690 Total Submissions: 168587 Given a string s consists of ...
随机推荐
- webpack 配置react脚手架(五):mobx
1. 配置项.使用mobx,因为语法时es6-next,所以先配置 .babelrc 文件 { "presets": [ ["es2015", { " ...
- 安装Genymotion模拟器(第三方)
优势: 启动速度更快 注册账户,下载可用的系统镜像,就可以使用. 官方网站: https://www.genymotion.com/account/login/ 选择的版本是带VirtualB ...
- Selenium常用API的使用java语言之8-模拟鼠标操作
通过前面例子了解到,可以使用click()来模拟鼠标的单击操作,现在的Web产品中提供了更丰富的鼠标交互方式, 例如鼠标右击.双击.悬停.甚至是鼠标拖动等功能.在WebDriver中,将这些关于鼠标操 ...
- 人们为什么在Python脚本的第一行上编写#!/ usr / bin / env python shebang?
在我看来,如果没有该行,文件运行相同. #1楼 您可以使用virtualenv尝试此问题 这是test.py #! /usr/bin/env python import sys print(sys.v ...
- 2015浙工大校赛-Problem C: 三角—— 费马大定理+勾股数
题目 有一个直角三角形三边为 A,B,C 三个整数.已知 C 为最长边长,求一组B,C,使得B和C最接近. (题目链接) 分析 打表找规律. 或者直接一点的枚举 $C-B$ 的值.(既然枚举 B 不现 ...
- 011_GoldWave软件安装及使用
(一)软件安装包: 链接:https://pan.baidu.com/s/15c5veooyA8bAYIAgLFOLjg提取码:jiis 复制这段内容后打开百度网盘手机App,操作更方便哦 (二)降低 ...
- 18 | 为什么这些SQL语句逻辑相同,性能却差异巨大?
在MySQL中,有很多看上去逻辑相同,但性能却差异巨大的SQL语句.对这些语句使用不当的话,就会不经意间导致整个数据库的压力变大. 我今天挑选了三个这样的案例和你分享.希望再遇到相似的问题时,你可以做 ...
- jQuery网页加载的不同方式
一.window.onload 代码是从上而下执行的,通过window.onload可以使事件在页面加载完毕再执行 注意:window.onload事件多个只会执行最下面的一个,前面的会被覆盖 < ...
- css3 2D变形(transform)移动、缩放、旋转、倾斜
一. translate(x,y) 或者translateX(x)或者translateY(y) 注意点:translateX(x)和translateY(y)大写X和Y:只写一个值,默认y=0. & ...
- CF516D Drazil and Morning Exercise【并查集,结论】
题目描述:一棵\(n\)个点的树,设\(d(u)=\max_{v\in V}\text{dis}(u,v)\),每次询问一个数\(l\),求一个最大的联通子图\(L\),使得\(\forall u,v ...