当前位置:网站首页>LeetCode_58(最后一个单词的长度)
LeetCode_58(最后一个单词的长度)
2022-07-01 04:37:00 【***】
题目描述:
给你一个字符串 s,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中 最后一个 单词的长度。
单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。
示例 1:
输入:s = “Hello World”
输出:5
解释:最后一个单词是“World”,长度为5。
示例 2:
输入:s = " fly me to the moon "
输出:4
解释:最后一个单词是“moon”,长度为4。
示例 3:
输入:s = “luffy is still joyboy”
输出:6
解释:最后一个单词是长度为6的“joyboy”。
提示:
1 <= s.length <= 104
s 仅有英文字母和空格 ’ ’ 组成
s 中至少存在一个单词
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;
}
}
边栏推荐
- RuntimeError: “max_pool2d“ not implemented for ‘Long‘
- Pytest automated testing - compare robotframework framework
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- VIM简易使用教程
- How to view the changes and opportunities in the construction of smart cities?
- CUDA development and debugging tool
- CF1638E. Colorful operations Kodori tree + differential tree array
- Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
- [recommended algorithm] C interview question of a small factory
- Shell之一键自动部署Redis任意版本
猜你喜欢
![[godot] unity's animator is different from Godot's animplayer](/img/51/48f40a7b6736d7f78040eabbbd3395.jpg)
[godot] unity's animator is different from Godot's animplayer

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

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

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

CF1638E. Colorful operations Kodori tree + differential tree array

LM小型可编程控制器软件(基于CoDeSys)笔记二十:plc通过驱动器控制步进电机

One click shell to automatically deploy any version of redis

MySQL winter vacation self-study 2022 12 (5)

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination

2022年上海市安全员C证考试题模拟考试题库及答案
随机推荐
Seven crimes of counting software R & D Efficiency
Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
Pytorch(二) —— 激活函数、损失函数及其梯度
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
(12) Somersault cloud case (navigation bar highlights follow)
Codeforces Round #721 (Div. 2)B1. Palindrome Game (easy version)B2. Palindrome game (hard version)
2022年G1工业锅炉司炉特种作业证考试题库及在线模拟考试
Advanced application of ES6 modular and asynchronous programming
TASK04|數理統計
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
RDF query language SPARQL
先有网络模型的使用及修改
Programs and processes, process management, foreground and background processes
This sideline workload is small, 10-15k, free unlimited massage
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
All in all, the low code still needs to solve these four problems
2022年聚合工艺考试题及模拟考试
1. Mobile terminal touch screen event