CODE 75: Length of Last Word
来源:互联网 发布:java程序的入口 编辑:程序博客网 时间:2024/06/17 08:26
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 int lengthOfLastWord(String s) {// Note: The Solution object is instantiated only once and is reused by// each test case.char[] cs = s.toCharArray();int lastLength = 0;int length = 0;for (int i = 0; i < cs.length; i++) {if ((cs[i] >= 'A' && cs[i] <= 'Z')|| (cs[i] >= 'a' && cs[i] <= 'z')) {length++;} else {if (length != 0) {lastLength = length;}length = 0;}}if (length != 0) {lastLength = length;}return lastLength;}
- CODE 75: Length of Last Word
- [leet code] 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
- 透明:让一切变得简单、坦诚
- 八皇后问题
- Bootstrap迁移系列 - Modal
- java中Pattern与Matcher之间的用法,正则表达式,用于拆分语句
- cocos2d-x 渲染机制深入解析(二)
- CODE 75: Length of Last Word
- Block语法
- 使用php-screw对php站点进行加密
- 黑马程序员 — 交通灯管理系统
- 第一个类的程序
- [剑指offer][面试题06]重建二叉树
- poj1321 棋盘问题
- Django 1.5.4 专题二 urls 和 view 提高
- iOS手势识别(转)