Length of Last Word
来源:互联网 发布:淘宝服装拍照技巧 编辑:程序博客网 时间:2024/05/29 15:57
-----QUESTION-----
Given a string ''
, return the length of last word in the string.
If the last word does not exist, return 0.
Note:
For example,
Given "Hello World"
,
return 5
.
-----SOLUTION-----
class Solution {public: int lengthOfLastWord(const char *s) { int len = strlen(s); int i = len-1; while(s[i]==32) i--; int lengthCounter = 0; for(;i>=0; i--) { if(s[i] == 32) break; lengthCounter++; } return lengthCounter; }};
0 0
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- 斯坦福大学公开课:iOS 7应用开发 (一)
- MySQL相关——局域网访问MySQL服务
- 快速排序-Java实现
- 异步 IO
- 视频编解码学习之一:理论基础
- Length of Last Word
- 二级管导通压降
- MySQL相关——MySQL针对varchar排序问题
- poj1201 Intervals,差分约束问题,spfa
- informix扩展表空间
- 一路风景——2013-2014年总结
- Hibernate入门经典实例
- python tornado
- SQL2005中的几种约束