Length of Last Word
来源:互联网 发布:命令行进入linux mysql 编辑:程序博客网 时间:2024/05/01 03:05
Solution 1
public class Solution { public int lengthOfLastWord(String s){ s = s.trim();//eliminate space characters in the head and tail if(s == null || s.length() == 0) return 0; for(int i = 0; i < s.length(); i++){ if(s.charAt(s.length()-1-i) == ' ') return i; if(i == s.length()-1) return i+1; } return -1; }
Solution 2
public int lengthOfLastWord(String s){ return s.trim().length() > 0 ? s.split("\\s+")[s.split("\\s+").length - 1].length() : 0; }
0 0
- 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
- Length of Last Word
- Length of Last Word
- hdu4686---Arc of Dream(矩阵)
- 数据库死锁的解决办法
- c#操作Excel图表----备份用
- 定制DataGridView快捷菜单ContextMenuStrip的关联事件
- GetUserDefaultUILanguage
- Length of Last Word
- 显示器分辨率和图像分辨率的关系
- JAVA JDK TOMCAT 版本问题
- 打印数组的组合
- Struts中的标签s:checkbox用处
- 挑战程序员---三角形
- SaaS平台开发人员和SaaS应用开发人员的分化对他们的技术结构有哪些不同的要求?这两类开发人员都需要具备哪些知识呢?
- 动态数组使用
- SharePoint菜鸟开发旅程