Skip to content

Commit 625b254

Browse files
authored
Create Felix.md
1 parent dd54252 commit 625b254

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2018.12.3-leetcode58/Felix.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
```javascript
2+
package leetcode.easy;
3+
/**
4+
* @author Felix
5+
* @date 2018年11月17日下午10:52:33
6+
@version 给定一个仅包含大小写字母和空格 ' ' 的字符串,返回其最后一个单词的长度。
7+
如果不存在最后一个单词,请返回 0 。
8+
说明:一个单词是指由字母组成,但不包含任何空格的字符串。
9+
示例:输入: "Hello World" 输出: 5
10+
*/
11+
public class LengthOfLastWord {
12+
public int lengthOfLastWord(String s) {
13+
if(s == null || s.trim().length() == 0)
14+
return 0;
15+
String[] str = s.split(" ");
16+
String res = str[str.length-1];
17+
18+
return res.length();
19+
}
20+
}
21+
22+
```

0 commit comments

Comments
 (0)