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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

LeetCode 58. Length of Last Word

2019-11-11 07:23:35
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(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.

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

代碼

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ā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴文县| 西林县| 和静县| 邓州市| 渑池县| 阿拉尔市| 白沙| 闽侯县| 清新县| 石屏县| 安塞县| 巧家县| 会东县| 新丰县| 昌乐县| 休宁县| 永新县| 天津市| 泸西县| 阜宁县| 铁岭县| 买车| 铜鼓县| 徐闻县| 玛沁县| 建阳市| 修文县| 唐海县| 达州市| 布尔津县| 麻江县| 高雄市| 民和| 周至县| 镇康县| 五大连池市| 腾冲县| 浑源县| 夏邑县| 北海市| 九龙城区|