【Leetcode】58. Length of Last Word
来源:互联网 发布:恺英网络王悦老婆 编辑:程序博客网 时间:2024/06/04 18:43
原题:
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.
public class Solution { public int lengthOfLastWord(String s) { s = s.trim(); if(s.indexOf(' ')==-1){ return s.length(); } return s.length() - s.lastIndexOf(' ') - 1; }}
用Java处理字符串就跟开挂一样。。
阅读全文
0 0
- 58. Length of Last Word Leetcode Python
- [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
- <LeetCode OJ> 58. Length of Last Word
- 58. Length of Last Word LeetCode
- 【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
- 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-java-58. Length of Last Word
- 策略模式用于封装系列的算法,这些算法通常被封装在一个被称为 Context 类中,客户端程序可以自由选择其中一种算法
- 疯狂的bLue
- 动态规划求解矩阵连乘
- POJ 1973 Software Company 笔记
- Android 进阶16:IntentService 使用及源码解析
- 【Leetcode】58. Length of Last Word
- 流程python学习笔记:第三章(2)
- 以空格为分隔符的字符串提取
- Sort
- Almost Sorted Array HDU
- (牛客网)构建乘积数组
- Qt笔记(1)连接 SQL Server 数据库
- 漠然的第一篇博客
- CMake 构建动态链接库