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

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

LeetCode 58. Length of Last Word

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

描述 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; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丘北县| 峡江县| 舒城县| 崇阳县| 隆德县| 扶沟县| 荔波县| 邳州市| 石河子市| 盘山县| 花莲市| 顺昌县| 金堂县| 承德市| 松阳县| 厦门市| 宁乡县| 华蓥市| 行唐县| 曲周县| 巴青县| 云和县| 赤水市| 福鼎市| 布尔津县| 龙海市| 神农架林区| 宜兰县| 宿松县| 渑池县| 夏河县| 榆树市| 遂昌县| 海原县| 桃江县| 临泉县| 中江县| 万荣县| 安福县| 郧西县| 遂宁市|