Skip to content

Commit ec4f94f

Browse files
authored
Create 58. Length of Last Word (#445)
2 parents a092920 + b528966 commit ec4f94f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

58. Length of Last Word

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public:
3+
int lengthOfLastWord(string s) {
4+
int n=s.size();
5+
int f;
6+
char p = ' ';
7+
for(int i=n-1;i>=0;i--){
8+
if(s[i] != p){
9+
f=i;
10+
break;
11+
}
12+
}
13+
int count=0;
14+
for(int i=f; i>=0; i--){
15+
if(s[i] == p)
16+
break;
17+
18+
count++;
19+
}
20+
21+
return count;
22+
23+
24+
}
25+
};

0 commit comments

Comments
 (0)