当前位置:网站首页>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;
}
}
边栏推荐
- Leecode question brushing record 1310 subarray XOR query
- LeetCode_35(搜索插入位置)
- 2022年T电梯修理题库及模拟考试
- Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
- 2022 t elevator repair new version test questions and t elevator repair simulation test question bank
- 先有网络模型的使用及修改
- 2022-02-15 (399. Division evaluation)
- Research on medical knowledge atlas question answering system (I)
- Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
- 2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
猜你喜欢

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

pytorch 卷积操作

Odeint et GPU

About the transmission pipeline of stage in spark

This sideline workload is small, 10-15k, free unlimited massage
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

Why is Internet thinking not suitable for AI products?

RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead

2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试

STM32扩展版 按键扫描
随机推荐
Why is Internet thinking not suitable for AI products?
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?
Odeint and GPU
JVM栈和堆简介
Pytorch(三) —— 函数优化
Shell之一键自动部署Redis任意版本
神经网络-卷积层
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
1. Mobile terminal touch screen event
Pytorch(一) —— 基本语法
pytorch神经网络搭建 模板
细数软件研发效能的七宗罪
Selenium opens the Chrome browser and the settings page pops up: Microsoft defender antivirus to reset your settings
2022 question bank and answers for safety production management personnel of hazardous chemical production units
【FTP】FTP常用命令,持续更新中……
Shell之分析服务器日志命令集锦
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
RuntimeError: mean(): input dtype should be either floating point or complex dtypes.Got Long instead
Odeint et GPU
神经网络-最大池化的使用