当前位置:网站首页>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;
}
};
边栏推荐
- Breaking the principle and introducing SQL, what does MongoDB want to do???
- Mysql索引结构
- [BJDCTF2020]Cookie is so stable-1|SSTI injection
- Another blast!Ali's popular MySQL advanced collection is open source, reaching P7
- 干货分享:小技巧大用处之Bean管理类工厂多种实现方式
- 结合实战,浅析GB/T28181(三)——实况点播
- int a=8,a=a++,a? int b=8,b=b+1,b?
- 关于File文件的相关知识
- Beijing, Shanghai and Guangzhou offline events丨The most unmissable technology gatherings at the end of the year are all gathered
- EasyNVS cloud management platform function reconstruction: support for adding users, modifying information, etc.
猜你喜欢

刷屏了!!!

C语言学习练习题:汉诺塔(函数与递归)

【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求

What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?

私有化部署的即时通讯平台,为企业移动业务安全保驾护航
![[BJDCTF2020]Cookie is so stable-1|SSTI injection](/img/48/34955bbe3460ef09a5b8213c7cc161.png)
[BJDCTF2020]Cookie is so stable-1|SSTI injection

重建丢失的数据

for循环的3个表达式执行顺序

Yilian: Activating the Value Potential of Data Elements and Unleashing the Innovation Dividend of SAS SSD

MySQL【多表查询】
随机推荐
[PostgreSQL] - 存储结构及缓存shared_buffers
Markdown 1 - 图文音视频等
for循环的3个表达式执行顺序
【Kaggle:UW-Madison GI Tract Image Segmentation】肠胃分割比赛:赛后复盘+数据再理解
MySQL【排序与分页】
[Go]四、模块和包、流程控制、结构体
datax开启hana支持以及dolphinscheduler开启datax任务
Anaconda\Scripts\pip-script.py is not present ? 解决方案
New:WebKitX ActiveX :::Crack
What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
ES6 Set与Map是什么,如何使用
Dry Goods Sharing: Various Implementation Methods of Bean Management Factory with Great Use of Small Skills
Dolphinscheduler stand-alone transformation
腾讯称电竞人才缺口200万;华为鸿蒙3.0正式发布;乐视推行每周工作4天半?...丨黑马头条...
no matching host key type found. Their offer: ssh-rsa
湖仓一体电商项目(一):项目背景和架构介绍
DeFi 巨头进军 NFT 领域 用户怎么看?
[SCTF2019]Flag Shop
常见的云计算安全问题以及如何解决
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇