当前位置:网站首页>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;
}
}
边栏推荐
- Day 52 - tree problem
- C language games (I) -- guessing games
- 2022 gas examination question bank and online simulation examination
- 2022年化工自动化控制仪表操作证考试题库及答案
- [2020 overview] overview of link prediction based on knowledge map embedding
- 分布式锁的实现
- 2022危险化学品生产单位安全生产管理人员题库及答案
- pytorch神经网络搭建 模板
- STM32扩展板 温度传感器和温湿度传感器的使用
- LM small programmable controller software (based on CoDeSys) note 20: PLC controls stepping motor through driver
猜你喜欢

Software testing needs more and more talents. Why do you still not want to take this path?

STM32 photoresistor sensor & two channel AD acquisition

Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling

神经网络-最大池化的使用

This sideline workload is small, 10-15k, free unlimited massage

The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

C#读写应用程序配置文件App.exe.config,并在界面上显示

2022 polymerization process test questions and simulation test

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor
随机推荐
分布式全局唯一ID解决方案详解
2022危险化学品生产单位安全生产管理人员题库及答案
LeetCode_53(最大子数组和)
如何看待智慧城市建设中的改变和机遇?
How do I sort a list of strings in dart- How can I sort a list of strings in Dart?
Ten wastes of software research and development: the other side of research and development efficiency
One click shell to automatically deploy any version of redis
Codeworks round 449 (Div. 1) C. Kodori tree template
2022年上海市安全员C证考试题模拟考试题库及答案
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
分布式数据库数据一致性的原理、与技术实现方案
Shell analysis server log command collection
2022-02-15 (399. Division evaluation)
C language games (I) -- guessing games
Leecode question brushing record 1332 delete palindrome subsequence
STM32 photoresistor sensor & two channel AD acquisition
How to choose the right server for website data collection?
STM32 光敏电阻传感器&两路AD采集
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
Difficulties in the development of knowledge map & the importance of building industry knowledge map