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

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

LeetCode 58. Length of Last Word

2019-11-11 06:12:18
字體:
供稿:網(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ā)表
主站蜘蛛池模板: 瓮安县| 汕尾市| 平乐县| 云和县| 滨州市| 奈曼旗| 江孜县| 天等县| 博客| 扎囊县| 新河县| 宁蒗| 海宁市| 芮城县| 精河县| 兴城市| 太仆寺旗| 衡水市| 仁布县| 淄博市| 淮北市| 承德县| 江孜县| 永嘉县| 恩平市| 宝清县| 平武县| 宝坻区| 郧西县| 湘阴县| 双江| 盖州市| 青田县| 尚志市| 金湖县| 西丰县| 庄浪县| 竹山县| 修文县| 昔阳县| 周宁县|