LeetCode#58. Length of Last Word
来源:互联网 发布:淘宝代理加盟商 编辑:程序博客网 时间:2024/06/06 04:25
- 题目:给定一个字符串(包括空格),返回这个字符串最后一个单词的长度
- 难度:Easy
- 思路:先用正则将字符串进行分割,分割后的数组中判断最后一个单词的长度,值得注意的是如果原始字符串只有空格,那么分割后的数组长度为空
- 代码:
public class Solution { public int lengthOfLastWord(String s) { int len = s.length(); if(s == null || len == 0){ return 0; } String[] strArray = s.split("\\s+"); if(strArray.length < 1){ return 0; } String last = strArray[strArray.length-1]; if(last == null){ return 0; }else{ return last.length(); } }}
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
- python3 下 tensorflow slim inceptionV4 问题修正与测试
- Android开发者关注的在线资源
- React 还是 Vue: 你应该选择哪一个Web前端框架?
- VS2010上的OpenCV的版本选择与配置
- JAVA 中 Redis与ehcache对比与使用
- LeetCode#58. Length of Last Word
- Linux 下三种方式设置环境变量
- bom操作
- ElasticSearchDSL查询模板之一(按日查询与按关键词聚类)
- eclipse导入项目报错
- 数值方法——资料
- json格式解析——入门
- 06-maven 初始化配置: 配置maven本地环境 settings.xml
- GTD软件比较和选用