LeeCode 58. Length of Last Word 计算字符串的最后的一个单词的长度
来源:互联网 发布:js toggle 控制隐藏 编辑:程序博客网 时间:2024/04/28 11:15
题目要求:
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.
说明:
记住使用 s.trim()方法用于将字符串前后的空格去掉
public class solution { public int lengthOfLastWord(String s) { //使用数组的方式进行处理 s = s.trim(); // s.trim() 除去字符串前后的所有的空格 if(s.isEmpty()) return 0; String[] strarr = s.split(" "); String strx= strarr[strarr.length - 1]; return strarr[strarr.length - 1].length(); }}
0 0
- LeeCode 58. Length of Last Word 计算字符串的最后的一个单词的长度
- 58. Length of Last Word (计算最后一个单词的长度)
- leetcode 58. Length of Last Word(C语言,计算最后一个单词的长度)19
- LeetCode------58. Length of Last Word(字符串中最后一个单词的长度)
- LeetCode Length of Last Word最后一个单词的长度
- Length of Last Word 最后一个单词的长度
- leetcode:Length of Last Word最后一个单词的长度
- [LeetCode] Length of Last Word - 最后一个单词的长度
- Length of Last Word 最后一个单词的长度
- LeetCode Length of Last Word(最后一个单词的长度)
- (LeetCode)Length of Last Word --- 最后一个单词的长度
- leetcode_58. Length of Last Word 字符串最后一个单词的长度,字符串分词
- LeetCode--Length of Last Word (计算最后一个单词的长度)Python
- Length of Last Word 统计最后一个字符串的长度
- Length of Last Word 字符串中最后一个单词的长度 @LeetCode
- 字符串中最后一个单词的长度 Length of Last Word
- LeetCode 58. Length of Last Word(最后一个单词的长度)
- Leetcode刷题记——58. Length of Last Word(最后一个单词的长度)
- 二维数组与指向数组的指针
- 关于CoreData的增、删、改、查 (1)
- 图书列表
- CentOS 7.2 配置Apache服务(httpd)--上篇
- java8 stream 操作
- LeeCode 58. Length of Last Word 计算字符串的最后的一个单词的长度
- HTML5 Server-Sent Events with Java Servlets example
- new Gson().toJson(object) null值不进行转换问题
- 重庆市noip2016模拟round4 BSOJ4874 排序
- java中equals方法的用法和“==”的用法
- 分布式系统下的纠删码技术(一) -- Erasure Code (EC)
- Mac idea 2016 注册码
- List、Map、Set、HashMap、HashSet、Hashtable
- Feature scaling