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 4eaff4d commit f278bd9Copy full SHA for f278bd9
2018.12.3-leetcode58/黎明初醒.md
@@ -0,0 +1,34 @@
1
+```
2
+class Solution {
3
+ public int lengthOfLastWord(String s) {
4
+ int len = s.length();
5
+ int flag = 0,count=0;
6
+ if((len==0)||(s==null)){
7
+ return 0;
8
+ }
9
+ if(len==1){
10
+ if(s.charAt(0)==' ')
11
+ {
12
13
14
+ else{
15
+ return 1;
16
17
18
+ for(int i=len-1;i>0;i--){
19
+ if(s.charAt(i)!=' '){
20
+ count++;
21
+ if(s.charAt(i-1)==' ')
22
23
+ return count;
24
25
+
26
27
28
+ if(s.charAt(0)==' ') {
29
30
31
+ return count+1;
32
33
+}
34
0 commit comments