当前位置:网站首页>[58] length of the last word [leetcode]
[58] length of the last word [leetcode]
2022-04-23 08:52:00 【Book opens autumn maple】
1. Title Description 
Give you a string
s
, It consists of several words , Words are separated by some space characters . Return string the last one The length of the word .word It's just letters 、 The largest substring that does not contain any space characters .
Example 1:
Input :s = "Hello World" Output :5 explain : The last word is “World”, The length is 5.Example 2:
Input :s = " fly me to the moon " Output :4 explain : The last word is “moon”, The length is 4.Example 3:
Input :s = "luffy is still joyboy" Output :6 explain : The last word is... In length 6 Of “joyboy”.Tips :
1 <= s.length <= 104
s
Only English letters and spaces' '
forms
At least one word exists in
2. Core code 
class Solution {
public int lengthOfLastWord(String s) {
String[] split = s.split(" ");
return split[split.length - 1].length();
}
}
3. Test code 
class Solution {
public int lengthOfLastWord(String s) {
String[] split = s.split(" ");
return split[split.length - 1].length();
}
}
// @solution-sync:end
class Main {
public static void main(String[] args) {
String s = "Hello World";
int result = new Solution().lengthOfLastWord(s);
System.out.println(result);
}
}
版权声明
本文为[Book opens autumn maple]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230818433547.html
边栏推荐
- BK3633 规格书
- OneFlow学习笔记:从Functor到OpExprInterpreter
- 政务中台研究目的建设目标,建设意义,技术创新点,技术效果
- Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
- Swagger document export custom V2 / API docs interception
- Latex paper typesetting operation
- Non duplicate data values of two MySQL query tables
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
- 资源打包关系依赖树
- Basic usage of synchronized locks
猜你喜欢
使用flask和h5搭建网站/应用的简要步骤
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
Automatic differentiation and higher order derivative in deep learning framework
OneFlow學習筆記:從Functor到OpExprInterpreter
Redis Desktop Manager for Mac(Redis可视化工具)
After a circle, I sorted out this set of interview questions..
LaTeX论文排版操作
BK3633 规格书
Introduction to matlab
cadence的工艺角仿真、蒙特卡洛仿真、PSRR
随机推荐
Star Trek's strong attack opens the dream linkage between metacosmic virtual reality
请提前布局 Star Trek突破链游全新玩法,市场热度持续高涨
政务中台研究目的建设目标,建设意义,技术创新点,技术效果
idea底栏打开services
Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
Test your machine learning pipeline
Single chip microcomputer nixie tube stopwatch
swagger文档导出自定义v2/api-docs拦截
2021 Li Hongyi's adaptive learning rate of machine learning
洋桃电子STM32物联网入门30步笔记二、CubeIDE下载、安装、汉化、设置
深度学习框架中的自动微分及高阶导数
LLVM之父Chris Lattner:编译器的黄金时代
MATLAB 画五星红旗
Failed to prepare device for development
idea打包 jar文件
Bk3633 specification
微信:获取单个标签所有人
企业微信应用授权/静默登录
2021李宏毅机器学习之Adaptive Learning Rate
xctf刷题小记