leetcode 58:Length of Last Word
来源:互联网 发布:泰国香米 知乎 编辑:程序博客网 时间:2024/06/08 00:53
原题:
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
.
代码如下: (C)
int lengthOfLastWord(char* s) { if(s==NULL) return 0; int length=strlen(s); if(length==0) return 0; int result=0; int flag=0; for(int n=length-1;n>=0;n--) { if(*(s+n)!=' ') { flag=1; result++; } if(*(s+n)==' '&&flag==1) { return result; } } return result;}唉最近被动态规划虐的有点蛋疼。。。,心情糟糕,感觉需要补一补数学知识了。。。
都是3ms。
阅读全文
0 0
- [leetcode 58] Length of Last Word
- leetcode-58 Length of Last Word
- Leetcode NO.58 Length of Last Word
- LeetCode #58 length of Last Word
- [LeetCode 58]Length of Last Word
- leetcode || 58、Length of Last Word
- LeetCode 58 Length of Last Word
- [Leetcode 58, easy] Length of Last Word
- Length of Last Word (leetCode 58)
- leetcode[58]:Length of Last Word
- 【leetcode c++】58 Length of Last Word
- leetcode 58:Length of Last Word
- LeetCode---(58)Length of Last Word
- leetcode-58-Length of Last Word
- Leetcode# 58 Length of Last Word
- [leetcode-58]Length of Last Word(c)
- leetcode 58: Length of Last Word
- leetCode #58 Length of Last Word
- 中国通信市场现状:错综复杂还需理清头绪
- jmeter个人学习之路--badboy录制脚本
- DWZ框架之关于返回Jason数据介绍
- 2017最新详解Android中对话框之DatePickerDialog与TimePickerDialog
- 网友:国产军用集成电路的真实水平惨不忍睹
- leetcode 58:Length of Last Word
- Pixhawk---烧写FMU/IO bootloader
- [LeetCode] 107. Binary Tree Level Order Traversal II
- loadrunner之常用函数()
- 无法解析的外部符号 "public: virtual struct CRuntimeClass
- 自学 Java 怎么入门?
- virutalenvwrapper 简单使用
- InvocationHandler和Proxy(Class)的动态代理机制详解
- 设计模式子普通工厂模式