当前位置:网站首页>LeetCode_ 58 (length of last word)
LeetCode_ 58 (length of last word)
2022-07-01 04:44:00 【***】
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 ’ ’ form
s At least one word exists in
class Solution {
public int lengthOfLastWord(String s) {
int res=0;
for (int i = s.length()-1; i >=0; i--) {
int num=(int)s.charAt(i);
if((num>122||num<65||(num>90&&num<97))&&res==0)continue;
else if((num>122||num<65||(num>90&&num<97))&&res!=0)break;
else if ((num>=97&&num<=122)||(num>=65&&num<=90)) res++;
}
return res;
}
}
边栏推荐
- Construction of Meizhou nursing laboratory: equipment configuration
- Common UNIX Operation and maintenance commands of shell
- 【FTP】FTP常用命令,持续更新中……
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
- 如何看待智慧城市建设中的改变和机遇?
- Pytorch(四) —— 可视化工具 Visdom
- Why is Internet thinking not suitable for AI products?
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
猜你喜欢

VR线上展览所具备应用及特色

Dataloader的使用

扩展-Fragment

OdeInt與GPU

Introduction to JVM stack and heap

C - detailed explanation of operators and summary of use cases

About the transmission pipeline of stage in spark
![[ue4] event distribution mechanism of reflective event distributor and active call event mechanism](/img/44/6a26ad24d56ddd5156f3a31fa7e0b9.jpg)
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
随机推荐
STM32扩展版 按键扫描
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
C -- array
Leecode records the number of good segmentation of 1525 strings
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
Applications and features of VR online exhibition
VIM简易使用教程
2022年上海市安全员C证考试题模拟考试题库及答案
One click shell to automatically deploy any version of redis
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
2022-02-15 (399. Division evaluation)
2022 gas examination question bank and online simulation examination
Pytest automated testing - compare robotframework framework
Pytorch(四) —— 可视化工具 Visdom
测量三相永磁同步电机的交轴直轴电感
数据加载及预处理
Pytorch(三) —— 函数优化
Difficulties in the development of knowledge map & the importance of building industry knowledge map
最长递增子序列及最优解、动物总重量问题
PgSQL failed to start after installation