Skip to content

Commit 221cb21

Browse files
author
cpppy
authored
Create 58_Length_of_Last_Word.cc
1 parent cf45ebb commit 221cb21

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

58_Length_of_Last_Word.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int lengthOfLastWord(string s) {
4+
int result=0;
5+
for(int i=0;i<s.size();++i){
6+
if(s[i]==' '){
7+
if(s[i+1]!=' '&&s[i+1]!='\0') result=0;
8+
}
9+
else{
10+
result++;
11+
}
12+
}
13+
return result;
14+
}
15+
};

0 commit comments

Comments
 (0)