当前位置:网站首页>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;
}
}
边栏推荐
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- One click shell to automatically deploy any version of redis
- VIM简易使用教程
- 2022年聚合工艺考试题及模拟考试
- Web server: how to choose a good web server these five aspects should be paid attention to
- 2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
- Software testing needs more and more talents. Why do you still not want to take this path?
- 2. Use of classlist (element class name)
- VR线上展览所具备应用及特色
- Maixll-Dock 使用方法
猜你喜欢

How to use maixll dock

The index is invalid

离线安装wireshark2.6.10

Maixll-Dock 快速上手
![[leetcode skimming] February summary (updating)](/img/62/0d0d9f11434e49d33754a2e4f2ea65.jpg)
[leetcode skimming] February summary (updating)

Task04 | statistiques mathématiques

TASK04|數理統計
![Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]](/img/aa/a255d225d71e6ba2b497f8d59f5f11.jpg)
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]

2022 t elevator repair new version test questions and t elevator repair simulation test question bank

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
随机推荐
Cmake selecting compilers and setting compiler options
Applications and features of VR online exhibition
Strategic suggestions and future development trend of global and Chinese vibration isolator market investment report 2022 Edition
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.2 multiple registration protocol (MRP)
Shell之分析服务器日志命令集锦
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
Basic exercise of test questions hexadecimal to decimal
Pytorch(四) —— 可视化工具 Visdom
slf4j 简单实现
TASK04|數理統計
Daily algorithm & interview questions, 28 days of special training in large factories - the 13th day (array)
pytorch神经网络搭建 模板
Kodori tree board
TASK04|数理统计
How to use maixll dock
软件研发的十大浪费:研发效能的另一面
Summary of acl2021 information extraction related papers
Leecode records the number of good segmentation of 1525 strings
Day 52 - tree problem
[difficult] sqlserver2008r2, can you recover only some files when recovering the database?