当前位置:网站首页>58. 最后一个单词的长度
58. 最后一个单词的长度
2022-07-30 12:42:00 【拽拽就是我】
leetcode力扣刷题打卡
题目:58. 最后一个单词的长度
描述:给你一个字符串 s,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中 最后一个 单词的长度。
单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。
解题思路
1、从头遍历比较麻烦,直接倒着遍历。
原代码##
class Solution {
public:
int lengthOfLastWord(string s) {
int ans = 0;
for (int i = s.size() - 1; i >= 0; --i) {
if (s[i] == ' ') continue;
while (i >= 0 && s[i] != ' ') {
ans++;
--i;
}
break;
}
return ans;
}
};
边栏推荐
- 缓存一致性
- 如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
- for循环的3个表达式执行顺序
- Analysis of AI recognition technology and application scenarios of TSINGSEE intelligent video analysis gateway
- 智能指针实现猜想
- These critical programs are missing or too old: ma
- 重建丢失的数据
- Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD
- ModelCoder状态机:对柴油机工况判断策略进行建模
- 腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
猜你喜欢

Win11打不开exe应用程序怎么办?Win11无法打开exe程序解决方法

使用百度EasyDL实现明厨亮灶厨师帽识别

MySQL【排序与分页】

Another blast!Ali's popular MySQL advanced collection is open source, reaching P7

【Kaggle比赛常用trick】K折交叉验证、TTA

和数集团:让智慧城市更智慧,让现实生活更美好

Homework 7.29 correlation function directory and file attributes related functions

New:WebKitX ActiveX :::Crack

常见的云计算安全问题以及如何解决

ModelCoder状态机:对柴油机工况判断策略进行建模
随机推荐
C#实现软键盘的制作
Markdown 1 - 图文音视频等
在 Scala 中读取整个文件
解码Redis最易被忽视的CPU和内存占用高问题
ES6 Set与Map是什么,如何使用
无人艇轨迹跟踪的预设性能抗扰控制研究
13-GuliMall 基础篇总结
关于香港高防IP需要关注的几个问题
Unity Beginner 6 - Simple UI production (blood bar production) and audio addition and NPC dialogue bubbles (2d)
What happened when the computer crashed?
多表联查的学习
Homework 7.29 correlation function directory and file attributes related functions
【河北工业大学】考研初试复试资料分享
和数集团:让智慧城市更智慧,让现实生活更美好
手慢无!阿里亿级流量高并发系统设计核心原理全彩笔记现实开源
Rust from entry to proficient 02-installation
云主机上的MongoDB被威胁,开启AUTH认证
datax enables hana support and dolphinscheduler enables datax tasks
刷屏了!!!
These critical programs are missing or too old: ma