Skip to content

Commit f278bd9

Browse files
authored
Create 黎明初醒.md
1 parent 4eaff4d commit f278bd9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

2018.12.3-leetcode58/黎明初醒.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return 0;
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+
return count;
30+
}
31+
return count+1;
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)