Length of Last Word LeetCode solution in C++

1
class Solution {
2
public:
3
int lengthOfLastWord(string s) {
4
int count = 0;
5
int n = s.size();
6
int i = n - 1;
7
while (i >= 0) {
8
if (s[i] == ' ') {
9
i--;
10
if (count > 0) {
11
break;
12
}
13
} else {
14
count++;
15
i--;
16
}
17
}
18
return count;
19
}
20
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0