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.
2 parents a092920 + b528966 commit ec4f94fCopy full SHA for ec4f94f
58. Length of Last Word
@@ -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
17
+
18
+ count++;
19
20
21
+ return count;
22
23
24
25
+};
0 commit comments