feat: 58_length_of_last_word
This commit is contained in:
parent
35a30abbf7
commit
8d403277c2
14
58_length_of_last_word/main.cpp
Normal file
14
58_length_of_last_word/main.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int lengthOfLastWord(string s) {
|
||||
int i = s.length() - 1, result = 0;
|
||||
|
||||
while (s[i] == ' ') i--;
|
||||
for (; i >= 0 && s[i] != ' '; i--, result++);
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user