Skip to content

Commit 98b7947

Browse files
authored
Implement lengthOfLastWord function in Solution class
1 parent d79de5a commit 98b7947

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Length of Last Word

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

0 commit comments

Comments
 (0)