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

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

LeetCode 58. Length of Last Word

2019-11-14 08:54:04
字體:
供稿:網(wǎng)友

描述 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; }};
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 罗江县| 秦皇岛市| 双牌县| 加查县| 抚宁县| 南宫市| 临汾市| 新干县| 西充县| 嫩江县| 荣成市| 阳春市| 高唐县| 林西县| 甘德县| 洪江市| 五家渠市| 华阴市| 平昌县| 朔州市| 乐山市| 固原市| 时尚| 常熟市| 丰顺县| 炎陵县| 曲麻莱县| 南投县| 兰州市| 文化| 花莲县| 武陟县| 阳城县| 黔东| 固始县| 清原| 浑源县| 休宁县| 南通市| 化隆| 田林县|