Skip to content

Commit 8c641f4

Browse files
authored
Create sourcema.md
1 parent 2fa28f1 commit 8c641f4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2018.12.3-leetcode58/sourcema.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# LeetCode 58
2+
class Solution {
3+
public int lengthOfLastWord(String s) {
4+
if (s == null || s.length() == 0) {
5+
return 0;
6+
}
7+
String str = s.trim();
8+
int length=0;
9+
for (int i=str.length()-1;i>=0;i--) {
10+
if (str.charAt(i) != ' ') {
11+
length++;
12+
} else {
13+
break;
14+
}
15+
}
16+
return length;
17+
}
18+
}

0 commit comments

Comments
 (0)