We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fca637a commit f37e7a9Copy full SHA for f37e7a9
2018.12.3-leetcode58/Sunny.md
@@ -0,0 +1,14 @@
1
+```java
2
+class Solution {
3
+ public int lengthOfLastWord(String s) {
4
+ if (s == null) return 0;
5
+ int i = s.lastIndexOf(" ");
6
+ if (i < 0) return s.length();
7
+ if (i == (s.length() - 1) && s.length() > 1) {
8
+ s = s.substring(0, i);
9
+ return lengthOfLastWord(s);
10
+ }
11
+ return s.substring(i+1, s.length()).length();
12
13
+}
14
+```
0 commit comments