LeetCode 58 Length of Last Word
来源:互联网 发布:网络直播一群无聊人 编辑:程序博客网 时间:2024/05/21 22:38
原题:(频率1)
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
.
题意:最后一个词的长度
代码和思路:
class Solution { public int lengthOfLastWord(String s) { //去掉首尾空格 s = s.trim(); if(s.length()==0 || s==null){ return 0; } char [] c = s.toCharArray(); int index = 0; int end = c.length; for(int i=0;i<c.length;i++){ if(c[i]==' '){ //最后一个字符串的开头 index = i+1; } } return end - index; }}
阅读全文
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
- 表单各种元素
- 原始编译r40的tinav2.1(取UART打印)(分色排版)
- eclipse使用CTRL+H Search 之后, 如何打开多个标签页
- 2017.10.19 起床困难综合征 思考记录
- linux 查找某目录下包含关键字内容的文件
- LeetCode 58 Length of Last Word
- SpringMVC+Spring+mybatis+redis项目从零开始--redis缓存策略和配置实现
- android studio安装模拟器的坑爹问题
- mongodb增加认证操作步骤
- ElementUI Table公共组件,快速完成table功能搭建
- tensorflow 用矩阵运算替换for循环 用tf.tile而不写for
- 欢迎使用CSDN-markdown编辑器
- Spring思维导图,让Spring不再难懂(mvc篇)
- Servlet笔记