LeetCode Length of Last Word 字符串
来源:互联网 发布:觉得自己很失败 知乎 编辑:程序博客网 时间:2024/04/27 17:39
思想:
只有字母、空格、'\0'三种类型的字符。
class Solution {public: int lengthOfLastWord(const char *s) { if(s == NULL) return 0; int length = 0; while(*s) { if(*s++!=' ') { length++; }else if(*s && *s!=' ') { length = 0; } } return length; }};
class Solution {public: int lengthOfLastWord(string s) { int length = 0; for(int i = s.length() - 1; i >= 0; --i) { if(s[i] != ' ') { length++; }else if(length != 0){ return length; } } return length; }};
0 0
- LeetCode Length of Last Word 字符串
- leetcode---Length of Last Word---字符串
- [leetcode] 【字符串】58. Length of Last Word
- leetcode:字符串之Length of Last Word
- LeetCode练习-字符串-length-of-last-word
- leetcode---length-of-last-word---字符串
- LeetCode: Length of Last Word
- LeetCode Length of Last Word
- LeetCode : Length of Last Word
- [Leetcode] Length of Last Word
- [LeetCode] Length of Last Word
- [LeetCode]Length of Last Word
- [leetcode]Length of Last Word
- Leetcode:Length of Last Word
- LeetCode-Length of Last Word
- [LeetCode] Length of Last Word
- [leetcode] Length of Last Word
- leetcode length of last word
- find命令的几个例子解析(-a,-o,-path,-wholename,-prnue,-print)
- Java_语法基础_谨慎包装类型的大小比较
- 小米note低配版(8974)专用TWRP2.8.6.1中文版recovery(单系统版)
- Android学习笔记2-项目目录结构分析
- 027:集合:在我的世界里,你就是唯一!
- LeetCode Length of Last Word 字符串
- NYOJ 448 寻找最大数 解题报告
- MySQL索引的创建、删除和查看
- 【ThinkingInJava】1、几个练习题
- Oracle作业队列入门图文解说
- Carthage 去中心化的Cocoa依赖管理器
- HDU 5201 The Monkey King(容斥)
- 男子独居洛阳死于家中9年才被发现 已成枯骨
- ios_label ios7自动换行