国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 石楼县| 武功县| 清苑县| 洪泽县| 德钦县| 南宫市| 康定县| 宁河县| 湄潭县| 潼关县| 加查县| 吴桥县| 奈曼旗| 正定县| 京山县| 舟山市| 鹤岗市| 越西县| 彭泽县| 武山县| 上思县| 嵊州市| 留坝县| 景东| 阳新县| 承德市| 治多县| 赫章县| 益阳市| 金堂县| 乐昌市| 上饶市| 高唐县| 南京市| 开江县| 凉城县| 宜君县| 洱源县| 洛扎县| 安陆市| 江门市|