当前位置:网站首页>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;
}
}
边栏推荐
- Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
- 1. Mobile terminal touch screen event
- Software testing needs more and more talents. Why do you still not want to take this path?
- Maixll-Dock 使用方法
- How to choose the right server for website data collection?
- 2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
- 2. Use of classlist (element class name)
- Difficulties in the development of knowledge map & the importance of building industry knowledge map
- Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and
- Grey correlation cases and codes
猜你喜欢

Odeint and GPU

LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target

Maixll-Dock 快速上手

Applications and features of VR online exhibition

Cmake selecting compilers and setting compiler options

OdeInt與GPU

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

Kodori tree board

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

Question bank and answers for chemical automation control instrument operation certificate examination in 2022
随机推荐
selenium打开chrome浏览器时弹出设置页面:Mircrosoft Defender 防病毒要重置您的设置
神经网络-使用Sequential搭建神经网络
What are permissions? What are roles? What are users?
Shell之一键自动部署Redis任意版本
Maixll-Dock 使用方法
2022 hoisting machinery command registration examination and hoisting machinery command examination registration
Use winmtr software to simply analyze, track and detect network routing
2022.2.7-2.13 AI industry weekly (issue 84): family responsibilities
Common interview questions ①
1. Mobile terminal touch screen event
Summary of acl2021 information extraction related papers
2022年化工自动化控制仪表操作证考试题库及答案
Day 52 - tree problem
Pytorch(三) —— 函数优化
2022年煤气考试题库及在线模拟考试
Leetcode learning - day 36
为什么香港服务器最适合海外建站使用
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
Task04 mathematical statistics
Basic exercise of test questions hexadecimal to decimal