LeedCode 之 Length of Last Word
来源:互联网 发布:搜了网络 韩富平 编辑:程序博客网 时间:2024/06/05 03:27
题目链接:Length of Last Word
这道题就相当的简单的,主要是对特殊字符串的处理,而且题目中说“If the last word does not exist, return 0.”我就一直以为当最后一个字符是“ ”,就表示要return0,实际不是这样的。其需要返回的是最后一个单词的长度,除非整个字符串中没有一个单词。
直接上代码就行:
public class Solution { public int lengthOfLastWord(String s) { int len = s.length(); if(len==0) return 0;//首先处理字符串为空的时候 String[] word; word = s.split(" "); int leng = word.length; if(leng==0) return 0;//在这里需要处理字符串中没有单词的情况下 int re = word[leng-1].length(); return re; }}
0 0
- LeedCode 之 Length of Last Word
- [leedcode oj 58]Length of Last Word
- [LeedCode OJ]#58 Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- Length of Last Word
- redis在linux下搭建
- (转)Java 8中你可能没用过的10个特性
- JavaWeb毕业设计项目-足球队管理系统(二)成品展示+业务介绍
- slf4j介绍及配置详解
- MyEclipse 2016 CI 添加反编译JadClipse插件
- LeedCode 之 Length of Last Word
- 谈谈设计模式
- leetcode 110-判断一棵树是否为平衡二叉树
- code blocks windows环境下的配置
- [李景山php] 20170505深入理解PHP内核[读书笔记]--第二章:用户代码执行-1
- HTML5读取input[type=file]中的图片
- eclipse gradle 在线安装
- SLF4J和log4j的整合使用
- 对象内存布局