国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 58. Length of Last Word

2019-11-11 06:54:06
字體:
來源:轉載
供稿:網友

描述 Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last Word in the string.

If the last word does not exist, return 0.

Note: A word is defined as a character sequence consists of non-space characters only.

For example, Given s = “Hello World”, return 5.

分析 字符串序列中最后一個word的長度。 順序掃描,記錄每個word的長度,返回即可。

代碼

class Solution {public: int lengthOfLastWord(string s) { int len = 0; for (size_t i = 0; i < s.size();) { if (s[i++] != ' ') ++len; else if (i < s.size() && s[i] != ' ') len = 0; } return len; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海安县| 毕节市| 龙游县| 衡东县| 东乡| 大理市| 库伦旗| 那坡县| 拉孜县| 乌鲁木齐县| 中西区| 乳山市| 东明县| 张家港市| 清远市| 青岛市| 广丰县| 祁阳县| 泸溪县| 连山| 固始县| 策勒县| 夏邑县| 华阴市| 新巴尔虎右旗| 朔州市| 济源市| 泸州市| 麻栗坡县| 黄骅市| 宁晋县| 连南| 临朐县| 瓦房店市| 满洲里市| 莱芜市| 资溪县| 曲水县| 博罗县| 仙居县| 图片|