feat: 58_length_of_last_word

This commit is contained in:
SquidSpirit 2025-02-17 23:24:16 +08:00
parent 35a30abbf7
commit 8d403277c2

View 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;
}
};