当前位置:网站首页>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;
}
}
边栏推荐
- Question bank and answers for chemical automation control instrument operation certificate examination in 2022
- Odeint and GPU
- STM32 光敏电阻传感器&两路AD采集
- 测量三相永磁同步电机的交轴直轴电感
- Dual contractual learning: text classification via label aware data augmentation reading notes
- JS image path conversion Base64 format
- 2022 question bank and answers for safety production management personnel of hazardous chemical production units
- Extension fragment
- VIM简易使用教程
- Common interview questions ①
猜你喜欢

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

Kodori tree board

STM32 光敏电阻传感器&两路AD采集

2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis

The design points of voice dialogue system and the importance of multi round dialogue

Offline installation of Wireshark 2.6.10

How to do the performance pressure test of "Health Code"

Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition

MySQL winter vacation self-study 2022 12 (5)

2022 polymerization process test questions and simulation test
随机推荐
技术分享| 融合调度中的广播功能设计
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
LeetCode_28(实现 strStr())
数据加载及预处理
Difference between cookie and session
2022 polymerization process test questions and simulation test
How to do the performance pressure test of "Health Code"
MySQL winter vacation self-study 2022 12 (5)
PgSQL failed to start after installation
RDF query language SPARQL
Simple implementation of slf4j
All in all, the low code still needs to solve these four problems
Pytest automated testing - compare robotframework framework
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
Extension fragment
[2020 overview] overview of link prediction based on knowledge map embedding
Pytorch(二) —— 激活函数、损失函数及其梯度
Dataloader的使用
VIM easy to use tutorial